public function actionFeedback() { $model = new Feedback(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post()) && $model->save()) { return 'Спасибо. Мы обязательно ответим вам в ближайшее время.'; } else { return 'Не удалось отправить информацию на сервер. Попробуйте чуть позже :('; } }
/** * Finds the Feedback model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Feedback the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Feedback::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Feedback::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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; } // grid filtering conditions $query->andFilterWhere(['status' => $this->status]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'message', $this->message])->andFilterWhere(['like', 'answer', $this->answer]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\grid\GridView; use backend\modules\feedback\models\Feedback; $this->title = 'Обратная связь'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="box box-primary"> <div class="box-body"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'created_at:date', 'email:email', 'message:ntext', ['attribute' => 'status', 'filter' => Feedback::getStatusArray(), 'value' => 'StatusName'], 'user_id', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}', 'contentOptions' => ['class' => 'actionColumn'], 'buttonOptions' => ['class' => 'btn btn-sm btn-default', 'style' => 'padding:1px 10px;']]]]); ?> </div> </div>
echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'email')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'message')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'answer')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'status')->dropDownlist(Feedback::getStatusArray()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Создать' : 'Обновить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div> </div>