yii中的自定义搜索下拉列表
我有一个包含3个表的数据库,yii中的自定义搜索下拉列表,yii,Yii,我有一个包含3个表的数据库,国家,城市和数据中心country是city的母公司,city是数据中心的母公司。在城市中,我添加了一个国家及其工作罚款的搜索下拉列表。我已经在数据中心添加了cites搜索下拉列表,它也可以正常工作,但现在我想在数据中心搜索国家下拉列表,如何做到这一点 国家数据中心中的代码搜索下拉列表,位于admin.php <?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'dat
国家
,城市
和数据中心
country
是city
的母公司,city
是数据中心的母公司。在城市
中,我添加了一个国家及其工作罚款的搜索下拉列表。我已经在数据中心添加了cites搜索下拉列表,它也可以正常工作,但现在我想在数据中心搜索国家下拉列表,如何做到这一点
国家数据中心中的代码搜索下拉列表,位于admin.php
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'data-centers-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'city.cityname'=>array(
'name'=>'cityid',
'value'=>'$data->city->cityname',
'filter'=>CHtml::listData(Cities::model()->findAll(array('order'=>'cityname')), 'id', 'cityname')
),
'city.country.countryname'=>array(
'name'=>'city.country.id',
'value'=>'$data->city->countryid',
'filter'=>CHtml::listData(Countries::model()->findAll(array('order'=>'countryname')), 'id', 'countryname')
),
'datacentername',
'datacentercode',
'lastupdatedon',
'createdon',
array(
'class'=>'CButtonColumn',
'template'=> '{view}{update}',
),
),
)); ?>
代替引用管理视图,你应该向我们展示数据中心管理员视图,数据中心模型Seli已经更新了代码,用模型和视图PLZ考虑现在看一看:
class DataCenters extends CActiveRecord
{
[...]
/**
* @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(
'lastupdatedby0' => array(self::BELONGS_TO, 'Users', 'lastupdatedby'),
'city' => array(self::BELONGS_TO, 'Cities', 'cityid'),
'servers' => array(self::HAS_MANY, 'Servers', 'datacenterid'),
);
}
[...]
/**
* 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('id',$this->id);
$criteria->compare('cityid',$this->cityid);
$criteria->compare('datacentername',$this->datacentername,true);
$criteria->compare('datacentercode',$this->datacentercode,true);
$criteria->compare('lastupdatedon',$this->lastupdatedon,true);
$criteria->compare('lastupdatedby',$this->lastupdatedby);
$criteria->compare('createdon',$this->createdon,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
[...]
}