【问题标题】:three table based relation display in yii gridviewyii gridview中基于三表的关系显示
【发布时间】:2014-02-04 10:07:58
【问题描述】:

我在网格视图中获得了基于外键关系的显示 ID。如何获取值而不是 id?我的 gridview 中的代码如下:

$criteria->compare('education.UniversityNameid',$this->UniversityName, true); 

我在代码中的网格视图

 array( 
             'name' => 'UniversityName',
             'type' => 'raw',
                'value'=>'(empty($data->education->UniversityNameid))? "" : Yii::app()->params["currencySymbol"]." ".$data->education->UniversityNameid',

       ),

【问题讨论】:

    标签: php gridview yii


    【解决方案1】:

    你必须像这样在你的模型“大学”中建立一个关系

    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(
                'UniversityName' => array(self::BELONGS_TO, 'University', 'UniversityNameid'),
            );
        }
    

    感谢您可以访问名称

    $data->education->UniversityName
    

    【讨论】:

    • 外键ID只获取大学ID,但大学表不同,看我的帖子清楚
    • 请发布有关您使用的模型的更多信息
    【解决方案2】:

    在你的模型中设置关系

    'u' => array(self::BELONGS_TO, 'University', 'UniversityNameid'),
    

    并像访问它一样

      'attributes'=>array(
    
                array('name'=>'u.UniversityName',
                'label'=>'University',),
    
    
       ),
    

    【讨论】:

    • Dency G B 但外键 id 仅基于获得 universityid 但大学表不同
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    • 2013-04-25
    • 2011-03-02
    • 1970-01-01
    相关资源
    最近更新 更多