fairy_demon 2011-05-25 09:46:08 3755次浏览 15条回复 0 0 0

一般列表那一列都是顯示類別的ID,YII怎麼在列表中顯示相對應類別ID的名稱......

  • 回复于 2011-05-25 09:47 举报

    不太明白,举例说明一下!

  • 回复于 2011-05-25 09:51 举报

    [attach]178[/attach]
    圖中那個框裏面是一個類別ID,我不想顯示ID,我要顯示相對應的ID的類別名稱

  • 回复于 2011-05-25 09:54 举报

    设置一下表关系吧?

  • 回复于 2011-05-25 09:57 举报

    不是很懂,能不能具體點啊

  • 回复于 2011-05-25 09:59 举报
    $this->widget('zii.widgets.grid.CGridView', array(
    	'id'=>'write-database-grid',
    	'dataProvider'=>$model->search(),
    	'filter'=>$model,
    	'columns'=>array(
    		'ID',
    		'composition_id',
    		'creat_time',
    		/*'words',
    		'sentence',
    		'model_essay',*/
    		array(
    			'class'=>'CButtonColumn',
    		),
    	),
    ));
    

    列表裏面是這麼寫的,我想'composition_id',這一列變成類別名稱不是ID

  • 回复于 2011-05-25 10:04 举报
    array(
      'name' => 'composition_id',
      'value' => '$data->其它属性',
    ),
    
  • 回复于 2011-05-25 10:08 举报

    能不能具體點啊,我是通過composition_id找到composition_title這個表裏面的title,怎麼寫啊?

  • 回复于 2011-05-25 10:15 举报

    你在Composition模型里面写个方法吧

    'value' => 'Composition::GetCompositionTitle($data->composition_id)'
    

    或者设置关系也可以

  • 回复于 2011-05-25 10:26 举报

    这样写是可以的,不过最好做一下关联。
    模型类代码:

    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(
            'maincates' => array(self::BELONGS_TO, 'Maincate', 'maincate_id'),
        );
    }
    array(
        'name'=>'maincate_id',
        'value'=>'$data->maincates->name',
        'htmlOptions'=>array(
            'width'=>'150',
        ),
    ),
    
  • 回复于 2011-05-25 11:10 举报
    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(
        'composition' => array(self::BELONGS_TO, 'composition_title', 'ID'),
      );
    }
    array(
      'name' => 'composition_id',
      'value'=>'$data-> composition -> title',
    ),
    

    我這樣還是出來不了啊,艦長

  • 回复于 2011-05-25 11:17 举报

    关联写的不对吧

  • 回复于 2011-05-25 12:07 举报
    'compositiontitle' => array(self::BELONGS_TO, 'CompositionTitle', 'composition_id'),
    

    compositiontitle這個是關聯名,CompositionTitle這個是關聯的那個類,composition_id這個是新聞列表裏面的ID

    view裏面是按照您說的那樣寫的

    array(
      'name' => 'composition_id',
      'value'=>'$data-> compositiontitle -> title',
      'htmlOptions'=>array(
      'width'=>'150',
    ),
    

    但是還是不行啊,還是報Property "CDataColumn.0" is not defined.這個錯啊,艦長幫幫忙看看啊

  • 回复于 2011-05-25 14:03 举报
    public function relations()
    {
      return array(
        'composition' => array(self::BELONGS_TO, 'CompositionTitle', 'composition_id'),
      );
    }
    

    视图中

    array(
      'name' => 'composition_id',
      'value'=>'$data-> composition -> title',
    ),
    
  • 回复于 2011-05-25 15:02 举报

    好吧,我需要拉一个列表,就像这个CGridView拉出来的一样,但是他的上面有个搜索块,这个,明显我是不想要的.
    后面的修改什么的,甚至,可以自己去写,这些都可以搞定.
    有没有其他的组件,可以只显示一个列表?或是这个组件中把那个搜索框去掉?我不需要啊不需要啊不需要....

  • 回复于 2011-05-25 15:10 举报

    这个这个,,,别压了..顶起来..求解决方案>

您需要登录后才可以回复。登录 | 立即注册