如何将模型search()数据分配给Yii 1中的CHtml :: listData?
我的代码:
//Get Company for dropdown
$model = new Company();
$companies = $model->search();
$companyList = CHtml::listData($companies,'id','company_name');
答案 0 :(得分:0)
你不应该这样做。默认情况下,search()方法返回CActiveDataProvider,它与CGridView一起使用,依此类推。如果您需要将其与CHtml::listData()
一起使用,请执行以下操作:
// Here you can set criteria to findAll if you need
$companies = Company::model()->findAll();
$companyList = CHtml::listData($companies,'id','company_name');