我是 PHP 和 Yii 框架的新手。如何在数据库中插入多个问题
这是表单 View 代码
<?php echo $form->textField($model,'questions',array('id'=>"content_#index#_question textBox")); ?>
<?php echo $form->textField($model,'questions',array('id'=>"content_#index#_question textBox")); ?>
这是我的 Controller
public function actionAdd_quick()
{
$model=new Question;
$answers=new Answers;
if(isset($_POST['Question'],$_POST['Answers']))
{
$model->attributes=$_POST['Question'];
$answers->attributes=$_POST['Answers'];
foreach ($model['questions'] as $value) {
$model->questions = $value;
}
$model->save();
Yii::app()->user->setFlash('add_quick','Thank you for ');
$this->refresh();
}
$this->render('add_quick',array('model'=>$model,'answers'=>$answers));
}
实际上我的过程是创建多个问题和答案,但现在出现错误,例如
使用我的代码“为 foreach() 提供的参数无效”以及如何向 mysql 表发送多个问题和答案...
最佳答案
改变这个
foreach ($model['questions'] as $value) {
$model->questions = $value;
}
$model->save();
关于这个
foreach ($model['questions'] as $value) {
$model->questions = $value;
$model->save();
}
关于php - 如何在 yii 中将多个值发送到 mysql 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19158080/