Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Ask::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'user_id', $this->user_id])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'ask', $this->ask]);
     return $dataProvider;
 }
Example #2
0
 public function actionAsk()
 {
     $model = new Ask();
     if (!\Yii::$app->user->identity) {
         $model->user_id = 'guest';
         $model->attributes = Yii::$app->request->post("Ask");
         if ($model->save(false)) {
             Yii::$app->session->setFlash("success_ask", "Ваш вопрос отправлен");
             return $this->goBack();
         }
     } else {
         $model->user_id = 'Авторизованный';
         $model->attributes = Yii::$app->request->post("Ask");
         if ($model->save(false)) {
             Yii::$app->session->setFlash("success_ask", "Ваш вопрос отправлен");
             return $this->goBack();
         }
     }
 }
Example #3
0
 /**
  * Finds the Ask model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Ask the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Ask::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }