Ejemplo n.º 1
0
 /**
  * Creates a new Consultation model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //if(!Yii::$app->user->can('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $model = new Consultation();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 public function actionAjaxAdd()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     if (Yii::$app->request->post('productId') && Yii::$app->request->post('question')) {
         $model = new Consultation();
         $model->user_id = Yii::$app->user->id;
         $model->username = Yii::$app->user->identity->username;
         $model->product_id = Yii::$app->request->post('productId');
         $model->question = Yii::$app->request->post('question');
         if ($model->save()) {
             return ['status' => 1];
         } else {
             return ['status' => -2];
         }
     }
     return ['status' => -1];
 }