Aqui los modelos de las tablas relacionadas
Estado
<?php
/**
* This is the model class for table "tbl_estado".
*
* The followings are the available columns in table 'tbl_estado':
* @property integer $id
* @property string $codedo
* @property string $estado
* @property integer $estatusreg
*
* The followings are the available model relations:
* @property TblMunicipio[] $tblMunicipios
*/
class TblEstado extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'tbl_estado';
}
/**
* @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('codedo, estado', 'required'),
array('estatusreg', 'numerical', 'integerOnly'=>true),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, codedo, estado, estatusreg', '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(
'tblMunicipios' => array(self::HAS_MANY, 'TblMunicipio', 'idestado'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'numero identificador de estado',
'codedo' => 'codigo del estado correspondiente',
'estado' => 'Estado',
'estatusreg' => 'estatus en el que encuentra el registro (activo - inactivo)',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('codedo',$this->codedo,true);
$criteria->compare('estado',$this->estado,true);
$criteria->compare('estatusreg',$this->estatusreg);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return TblEstado the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
protected function beforeSave()
{
$this->estado = strtoupper($this->estado);
return parent::beforeSave();
}
}
Municipio
<?php
/**
* This is the model class for table "tbl_municipio".
*
* The followings are the available columns in table 'tbl_municipio':
* @property integer $id
* @property integer $idestado
* @property string $codmun
* @property string $municipio
* @property integer $estatusreg
*
* The followings are the available model relations:
* @property TblParroquia[] $tblParroquias
* @property TblEstado $idestado0
*/
class TblMunicipio extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'tbl_municipio';
}
/**
* @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('idestado, codmun, municipio', 'required'),
array('idestado, estatusreg', 'numerical', 'integerOnly'=>true),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, idestado, codmun, municipio, estatusreg', '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(
'tblParroquias' => array(self::HAS_MANY, 'TblParroquia', 'idmunicipio'),
'idestado0' => array(self::BELONGS_TO, 'TblEstado', 'idestado'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'numero identificador de municipio',
'idestado' => 'Idestado',
'codmun' => 'codigo correspondiente a este municipio',
'municipio' => 'Municipio',
'estatusreg' => 'estatus en el que encuentra el registro (activo - inactivo)',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('idestado',$this->idestado);
$criteria->compare('codmun',$this->codmun,true);
$criteria->compare('municipio',$this->municipio,true);
$criteria->compare('estatusreg',$this->estatusreg);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return TblMunicipio the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
Parroquia
<?php
/**
* This is the model class for table "tbl_parroquia".
*
* The followings are the available columns in table 'tbl_parroquia':
* @property integer $id
* @property integer $idmunicipio
* @property string $codpar
* @property string $parroquia
* @property integer $estatusreg
*
* The followings are the available model relations:
* @property TblMunicipio $idmunicipio0
* @property TblEstructura[] $tblEstructuras
* @property TblDependencias[] $tblDependenciases
*/
class TblParroquia extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'tbl_parroquia';
}
/**
* @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('idmunicipio, codpar, parroquia', 'required'),
array('idmunicipio, estatusreg', 'numerical', 'integerOnly'=>true),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, idmunicipio, codpar, parroquia, estatusreg', '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(
'idmunicipio0' => array(self::BELONGS_TO, 'TblMunicipio', 'idmunicipio'),
'tblEstructuras' => array(self::HAS_MANY, 'TblEstructura', 'idparroquia'),
'tblDependenciases' => array(self::HAS_MANY, 'TblDependencias', 'idparroquia'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'numero identificador de parroquia\r\n\r\n',
'idmunicipio' => 'Idmunicipio',
'codpar' => 'codigo correspondiente a la parroquia',
'parroquia' => 'nombre de la parroquia',
'estatusreg' => 'estatus en el que encuentra el registro (activo - inactivo)',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('idmunicipio',$this->idmunicipio);
$criteria->compare('codpar',$this->codpar,true);
$criteria->compare('parroquia',$this->parroquia,true);
$criteria->compare('estatusreg',$this->estatusreg);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return TblParroquia the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
este es mi form_
<!-- ************************************************************************************************ -->
<!-- ************************************************************************************************ -->
<!-- ************************************************************************************************ -->
<div class="row">
<?php echo $form->labelEx($model,'Estado'); ?>
<?php
echo $form->dropDownList($model,'idparroquia0.idmunicipio0.idestado0.id',CHtml::listData(TblEstado::model()->findAll(),'id','estado'),
array(
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('TblEstructura/Selectmunicipio'),
'update' => '#'.CHtml::activeId($model,'id_municipio'), /* deberias cambiar tus id y renombrarlos decuardo a tu tabla ejem: tabla municipios seria id_municipio, tabla estado seria id_estado de tal manera que no te saque errore por poner el mismo nombre a un campo*/
),'prompt' => 'Seleccione un Estado...'
)
);
?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Municipio'); ?>
<?php
echo $form->dropDownList($model,'idparroquia0.idmunicipio0.id',CHtml::listData(TblMunicipio::model()->findAll(),'id','Municipio'),
array(
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('TblEstructura/SelectParroquia'),
'update' => '#'.CHtml::activeId($model,'id_parroquia'),
),
)
);
?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Parroquia'); ?>
<?php echo $form->dropDownList($model,'idparroquia',array()); ?>
</div>
<!-- ************************************************************************************************ -->
<!-- ************************************************************************************************ -->
<!-- ************************************************************************************************ -->
El error me dice:
La propiedad "TblEstructura"."idparroquia0.idmunicipio0.idestado0.id" no se encuentra definida.
/var/www/yii/framework/db/ar/CActiveRecord.php(145)
133 */
134 public function __get($name)
135 {
136 if(isset($this->_attributes[$name]))
137 return $this->_attributes[$name];
138 elseif(isset($this->getMetaData()->columns[$name]))
139 return null;
140 elseif(isset($this->_related[$name]))
141 return $this->_related[$name];
142 elseif(isset($this->getMetaData()->relations[$name]))
143 return $this->getRelated($name);
144 else
145 return parent::__get($name);
146 }
Se que esta mal llamdo el id del estado y municipio pero no se de que otra manera llamarlo. ademas recuerden que los ID de las tablas se llaman "id" ya cuando son claves foraneas se llaman "idtabla" (por ejemplo)