我创建了一个文章和评论模型,并在两者上都有 CRUD。它完美地工作。我现在需要的是在 Comment Crud 中显示 article.title 字段而不是 comment.articleid。我怎样才能做到这一点?
这就是我卡住的地方。我不知道下一步该怎么做或者这是否正确:
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(
'article'=>array(self::BELONGS_TO, 'Article', 'articleid')
);
}
编辑:
这是我的代码 admin.php 查看文件:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'comment-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'commentid',
'articleid',
'content',
'author',
'email',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
谢谢。