/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($id) { $modelOrder = Order::model()->findByPk($id); $model = new SparePartsOrder(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['SparePartsOrder'])) { $model->spare_parts_id = $_POST['SparePartsOrder']['spareParts']; // $model->attributes = $_POST['SparePartsOrder']; var_dump($model->attributes); if ($model->validate()) { if (isset($_POST['SparePartsOrder']['spareParts'])) { $arraySpareParts = $_POST['SparePartsOrder']['spareParts']; foreach ($arraySpareParts as $spareParts) { $model = new SparePartsOrder(); $model->order_id = $modelOrder->id; $model->spare_parts_id = $spareParts; $model->save(false); } } $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model, 'modelOrder' => $modelOrder)); }