/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Screen'])) { $model->attributes = $_POST['Screen']; if ($model->save()) { if (isset($_POST['Blocks'])) { $blocks = $_POST['Blocks']; Window::model()->deleteAllByAttributes(array('screen_id' => $model->id)); foreach ($blocks as $name => $block) { $windowModel = new Window(); $windowParams = explode(",", $block); $window = array('screen_id' => $model->id, 'name' => $name, 'height' => $windowParams[1], 'width' => $windowParams[0], 'top' => $windowParams[3], 'left' => $windowParams[2], 'authorId' => Yii::app()->user->getId()); $windowModel->attributes = $window; $windowModel->save(); } } $this->redirect(array('view', 'id' => $model->id)); } } $windows = Window::model()->findAllByAttributes(array('screen_id' => $model->id)); $this->render('update', array('model' => $model, 'windows' => $windows)); }