【发布时间】:2014-09-18 08:29:57
【问题描述】:
我必须在 Yii 框架中制作一个 webapp。
我想使用 select2 并想在我的数据库中使用一列..
这是我的代码
<?php
$users= User::model()->findAll(array(
'select'=>'name',
));
echo CHtml::textField('User','',array('id'=>'user', 'style'=>'width:300px;'));
$this->widget('ext.select2.ESelect2',array(
'selector'=>'#user',
'options' => array(
'tags'=> $names,
),
));
?>
当我使用 vardump 检查变量 $users 中的内容时,我得到了这个:
数组 ( [0] => 用户对象 ( [_new:CActiveRecord:private] => [_attributes:CActiveRecord:private] => 数组 ( [名称] => "asd" )
[_related:CActiveRecord:private] => Array
(
)
[_c:CActiveRecord:private] =>
[_pk:CActiveRecord:private] =>
[_alias:CActiveRecord:private] => t
[_errors:CModel:private] => Array
(
)
[_validators:CModel:private] =>
[_scenario:CModel:private] => update
[_e:CComponent:private] =>
[_m:CComponent:private] =>
)
[1] => User Object
(
[_new:CActiveRecord:private] =>
[_attributes:CActiveRecord:private] => Array
(
[name] => "assss"
)
[_related:CActiveRecord:private] => Array
(
)
[_c:CActiveRecord:private] =>
[_pk:CActiveRecord:private] =>
[_alias:CActiveRecord:private] => t
[_errors:CModel:private] => Array
(
)
[_validators:CModel:private] =>
[_scenario:CModel:private] => update
[_e:CComponent:private] =>
[_m:CComponent:private] =>
)
还有更多。
但我唯一想要的是这个:[name] => "assss" .
我想我也使用了 foreach 循环或类似的东西,因为 select2 想要一个“清晰”的数组。 你们知道怎么做吗?
【问题讨论】:
-
对不起!我的意思是 print_r 不是 vardump。
标签: php mysql yii jquery-select2