我正在尝试从用户那里获得多项选择,但在提交后我收到错误:
htmlspecialchars()期望参数1为字符串,给定数组为
<?php echo $form->labelEx($model, 'Books_read'); ?>
<div>
<?php $opts = array('booka' => 'Book A', 'bookb' => 'Book B', 'bookc' => 'Book C ', 'bookd' => 'Book D','booke' => 'Book E','bookf' => 'Book F');
echo $form->checkBoxList($model, 'Books_read', $opts, array(
'class' => 'checkbox',
'multipe' => 'multiple',
'template' => '{input}{label}',
'separator' => '<br/>',
'labelOptions' => array('style' =>'margin: 2px 0px 2px 4px;'),
'style' => 'float:left;',)); ?>
</div>
<?php echo form->error($model,'Books_read '); ?>
<div style="clear: both;"></div>
数据库中的数据类型:text(适用于其他形式)
模型类:
protected function afterFind() {
if ($this->isJSON($this->Books_read))
{
$this->Books_read = json_decode($this->Books_read);
}
return parent::afterFind();
}
答案 0 :(得分:0)
如下所示编写表单元素: -
echo $form->checkBoxList(
$model,
'Books_read',
$opts,
'htmlOptions' => array( // add htmlOptions
'labelOptions' => array(
// code
)
)
);