In my model I have attribute - specifications:
class Category extends CActiveRecord
{
private $_specifications = array();
public function getSpecifications()
{
return $this->_specifications;
}
public function setSpecifications($specifications)
{
$this->_specifications = implode(', ', $specifications);
}
So I want specifications to be an array.
My view file:
<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>
When I send form I get an error:
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 }
I've tried to disable encoding:
<?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')); ?>
But in that case it's another error:
Array to string conversion
...
2216 $html .= ' ' . $name . '="' . ($raw ? $value : self::encode($value)) . '"';
Can anybody give an advice, what should I do to pass an array from form? Thanks.