Hi I’m a newbie in yii
I want to ask, how to save data array into a database?
My case I want to save the data which is input from multiple row
but the problem that could have saved it from just one field that is only from array 0
My actionCreate
public function actionCreate($idar) {
$model = new TbSnSpare;
if (isset($_POST[‘TbSnSpare’])) {
$model->attributes = $_POST[‘TbSnSpare’];
$model->id_spare = $idar;
if (isset($_POST[‘serial_number’])) {
$total = count($_POST[‘serial_number’]);
for ($i = 0; $i < $total; $i++) {
if (isset($_POST[‘serial_number’][$i])) {
$model->serial_number = $_POST[‘serial_number’][$i];
$model->save();
}
}
$this->redirect(array(‘view’, ‘id’ => $model->id_sn));
}
}
$this->render(‘create’, array(
‘model’ => $model,
));
}
Please help me…