public function actionCreate() { $model = new Rental(); if (isset($_POST['Rental'])) { $model->setAttributes($_POST['Rental']); if ($model->save()) { if (Yii::app()->getRequest()->getIsAjaxRequest()) { Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->rental_id)); } } } $this->render('create', array('model' => $model)); }
public function actionEditableCreator() { if (isset($_POST['Rental'])) { $model = new Rental(); $model->attributes = $_POST['Rental']; if ($model->save()) { echo CJSON::encode($model->getAttributes()); } else { $errors = array_map(function ($v) { return join(', ', $v); }, $model->getErrors()); echo CJSON::encode(array('errors' => $errors)); } } else { throw new CHttpException(400, 'Invalid request'); } }