0

我有一个包含 3 个表、countriescities的数据库datacenterscountry是 的父级city并且city是 的父级datacenter。在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,
        ));
    }

    [...]
}
4

0 回答 0