Yiiwheels选择盒子协会与模型

时间:2014-01-17 22:51:22

标签: php yii yii-extensions

我正在尝试用yiiwheels select widget替换yii默认选择小部件。

使用yii选择小部件的代码

<?php echo $form->dropDownList($model,'branch_id', CHtml::listData(Branches::model()->findAll(array('order' => 'branch_name')),'id','branch_name'));?>

想要得到这样的东西

<?php $this->widget('yiiwheels.widgets.formhelpers.WhSelectBox',array('name' => 'branch_id', 'size' => 'input-large', 'model' => $model, 'data' => CHtml::listData(Branch::model()->findAll(array('order' => 'branch_name')),'id','branch_name')));?>

我在表单提交时收到错误,表明branch_id字段不能为空。

如何将其与当前表单模型相关联?

以下是Yiiwheels API docs

的链接

1 个答案:

答案 0 :(得分:0)

我不得不使用'name'字段,而是使用'attribute'字段。

<?php $this->widget('yiiwheels.widgets.formhelpers.WhSelectBox',array('attribute' => 'branch_name', 'size' => 'input-large', 'model' => $model, 'data' => CHtml::listData(Branch::model()->findAll(array('order' => 'branch_name')),'id','branch_name')));?>

抱歉!我的错!