/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($cat_id = null) { if (Yii::app()->user->checkAccess($this->id . '.' . $this->action->id)) { $model = new PaymentType(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['PaymentType'])) { $model->attributes = $_POST['PaymentType']; $model->category_id = $cat_id; if ($model->save()) { if (Yii::app()->request->isAjaxRequest) { echo CJSON::encode(array('status' => 'success', 'div' => 'Payment Type successfully added.')); exit; } else { // Yii::app()->user->setFlash('success', 'Payment Type added successfully!'); $this->redirect(Yii::app()->user->returnUrl); } } } // $model->category_id = $cat_id; if (Yii::app()->request->isAjaxRequest) { echo CJSON::encode(array('status' => 'failure', 'div' => $this->renderPartial('_form', array('model' => $model), true, true))); exit; } else { $this->render('create', array('model' => $model, 'cat_name' => Category::model()->findByPk($cat_id)->getFullCategory())); } } else { $this->accessDenied(); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new PaymentType(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['PaymentType'])) { $model->attributes = $_POST['PaymentType']; if ($model->save()) { if (!empty($_POST['yt1'])) { Yii::app()->user->setFlash('paymentType-created', "¡El tipo de pago <b><i>"{$model->name}"</i></b> fue creado exitosamente!"); $model = new PaymentType(); } else { $this->redirect(array('view', 'id' => $model->id)); } } } $this->render('create', array('model' => $model)); }