Answer the question
In order to leave comments, you need to log in
How to accept an array in yii?
Good afternoon, faced such problem:
1. in model created public property $faq_array;
2. set the rules for it with array('faq_array','safe')
3. the bottom line is that for the record I throw a few questions and answers - organized with the help of www.yiiframework.com/extension/jqrelcopy
4. in the behavior I prescribe:
public function beforeSave($event){
print_r($this->owner->faq_array);
...
}
This produces no results. But if instead of print_r I write: print_r($_POST);
Then when I print the array, the one I need comes out:
[faq_array] => Array
(
[question] => Array
(
[0] => Вопрос 1
[1] => Ответ 1
)
[answer] => Array
(
[0] => Вопрос 2
[1] => Ответ 2
)
)
[faq_array] => Array
(
[0] =>Array
(
[question] => Вопрос 1
[answer] => Ответ 1
)
[1] =>Array
(
[question] => Вопрос 2
[answer] => Ответ 2
)
)
<div class="alert alert-info copy_faq">
<?php echo CHtml::label('Вопрос',''); ?>
<?php echo CHtml::textField('faq_array[question][]',''); ?>
<?php echo CHtml::label('Ответ',''); ?>
<?php echo CHtml::textArea('faq_array[answer][]', ''); ?>
</div>
Answer the question
In order to leave comments, you need to log in
I hope there is?
$model = new Model;
$model->attributes = $_POST;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question