开发者

how to use drop down list of a cgrid view in yii?

Hi, I know this should be really simple but I am just too new to php and yii. So, please, bear with me. I have a table named thefriends which has columns(thepals,address,phone numbers). Now the admin page uses a CGridView to list all these friends in the usual format. I want the text boxes to be replaced by drop down menus. I know it can be done by using the following code in views/Thefriends/admin.php

'columns'=>array(
  'id',
  'array'(
   'name'='thepals',
   'filter'=array(1=>'alice',2=>'jenna'),

)

But as you see I have to populate the values myself, instead I want all the values to be prepopulated开发者_开发技巧 from the particular column.. please help..


Use a CHtml::ListData object as the filter. For instance, let's assume that your related thePals table has the columns id and name.

'columns' => array(
    'id',
    array(
        'name' => 'thepals',
        'filter' => CHtml::listData(thePals::model()->findAll(),'id','name'),
    ...
),
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜