在我的模型中,我有属性 - 规格:
class Category extends CActiveRecord
{
private $_specifications = array();
public function getSpecifications()
{
return $this->_specifications;
}
public function setSpecifications($specifications)
{
$this->_specifications = implode(', ', $specifications);
}
所以我希望规范是一个数组。
我的视图文件:
<div id="specifications" class="row">
<?php echo $form->labelEx($model,'specifications'); ?>
<?php echo $form->textField($model,'specifications',array('rows'=>6, 'cols'=>50, 'name'=>'Category[specifications][0]', 'class' => 'clonedInput')); ?>
<?php echo $form->textField($model,'specifications',array('rows'=>6, 'cols'=>50, 'name'=>'Category[specifications][1]', 'class' => 'clonedInput')); ?>
<?php echo $form->error($model,'specifications'); ?>
</div>
当我发送表单时,我收到一个错误:
htmlspecialchars() expects parameter 1 to be string, array given
...
public static function encode($text)
84 {
85 return htmlspecialchars($text,ENT_QUOTES,Yii::app()->charset);
86 }
我试图禁用编码:
<?php echo $form->textField($model,'specifications',array('encode'=>false, 'rows'=>6, 'cols'=>50, 'name'=>'Category[specifications][0]', 'class' => 'clonedInput')); ?>
<?php echo $form->textField($model,'specifications',array('encode'=>false, 'rows'=>6, 'cols'=>50, 'name'=>'Category[specifications][1]', 'class' => 'clonedInput')); ?>
但在这种情况下,这是另一个错误:
Array to string conversion
...
2216 $html .= ' ' . $name . '="' . ($raw ? $value : self::encode($value)) . '"';
任何人都可以提供建议,我应该怎么做才能从表单中传递一个数组?谢谢。