Verificar que no existe una variable

Buenos Dias amigos,

espero recibir de su ayuda en cuanto a este frameworks que voy conociendo recientemente…

Mi problema es el siguiente… pasa que tengo 2 tablas netamente iguales… una de personas naturales y otras jurídicas, y tengo en un formulario un campo que hace referencia al campo de de esas tablas para que busque… al buscar ella debe decirme que si el resultado es nulo pasa a buscar en la siguiente tabla… mas o menos ese es el proceso… aqui les dejo el codigo

Este




	public function rules()

	{

		return array(

			//buscar localizador

			array('LOCALI','ValLocalizador'),

			

		);

	}



Busco en mi funsion que me apunta a 2 clases iguales solo que con tablas distintas…




	public function ValLocalizador($attribute, $params)

	{

		if(!empty($this->$attribute))

		{

			$err = false;

			$cw  = LocCierre::model()->find(array('condition'=>'LOCALI="'.$this->$attribute.'"'));


			if($cw){ $err = true; } else {

				$ad  = LocCierreJuridico::model()->find(array('condition'=>'LOCALI="'.$this->$attribute.'"'));

				if($ad){ $err = true; } else {

					$in  = LocCierreJuridico::model()->find(array('condition'=>'LOCALI="'.$this->$attribute.'"'));

					if($in){ $err = true; }

				}

			}


			//error

			if ($err)

				$this->addError($attribute, 'El correo electrónico ya ha sido registrado.');

		}

	}



Modelo







/**

 * This is the model class for table "loc_cierre".

 *

 * The followings are the available columns in table 'loc_cierre':

 * @property integer $LOCALI

 * @property integer $NROSEM

 * @property integer $DIAG1

 */

class LocCierre extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @param string $className active record class name.

	 * @return LocCierre the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'loc_cierre';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('LOCALI, NROSEM, DIAG1', 'numerical', 'integerOnly'=>true),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('LOCALI, NROSEM, DIAG1', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'LOCALI' => 'Locali',

			'NROSEM' => 'Nrosem',

			'DIAG1' => 'Diag1',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('LOCALI',$this->LOCALI);

		$criteria->compare('NROSEM',$this->NROSEM);

		$criteria->compare('DIAG1',$this->DIAG1);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}


	public function getSDcierre() {

		return $this->NROSEM . '-' . $this->DIAG1;

	}

}



Que estoy haciendo mal que no me esta buscando ni mostrando error alguno para guiarme

Buenas.

Muy confusa la pregunta, pero a ver si damos.

En tu modelo LocCierre no tienes ninguna regla que valide lo que tu quieres (ValLocalizador).

Tanto en LocCierre como en LocCierreJuridico debes añadir sendas reglas tal que así:




array('LOCALI','ValLocalizador'),



Un saludo.