yii中的自定义搜索下拉列表

时间:2012-10-23 07:24:28

标签: yii

我有一个包含3个表的数据库,countriescitiesdatacenterscountrycity的父级,citydatacenter的父级。在cities我添加了一个国家/地区的搜索下拉列表及其工作正常。我在数据中心添加了引用搜索下拉列表,它也工作正常,但现在我希望数据中心的国家搜索下拉列表,如何做。

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}',
        ),
    ),
)); ?>

型号代码:

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,
        ));
    }

    [...]
}

0 个答案:

没有答案