public function actionRequest($type) { $this->layout = '/default'; $model = new Request(); $model->type = $type; if ($model->load($_POST) && $model->save()) { $title = 'Новая заявка на получение карты на сайте: ' . Yii::$app->name; Yii::$app->session->setFlash('success', 'Ваша заявка успешно создана.'); $email = Yii::$app->params['email']; if (Yii::$app->mailer->compose('@app/modules/discount/views/default/mail/request', ['model' => $model, 'title' => $title])->setFrom($email->from)->setTo($email->to)->setSubject($title)->send()) { $this->redirect(['/cms/default/success']); } } else { return $this->render('request', ['model' => $model]); } }
/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new User(); $profile = new Profile(); $requestId = Yii::$app->request->get('requestId'); if ($requestId) { $request = Request::findOne($requestId); $request->fillData($profile); $request->fillData($model); } if ($model->load(Yii::$app->request->post()) && $model->save()) { $profile->load($_POST); $profile->userId = $model->id; $profile->save(); if ($requestId) { $request->status = Request::STATUS_DONE; $request->userId = $model->id; $request->dateActivate = date('Y-m-d H:i:s'); $request->save(false, ['status', 'userId']); } return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model, 'profile' => $profile]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Request::find()->with(['city']); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['status' => SORT_ASC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'cityId' => $this->cityId, 'dateCreate' => $this->dateCreate, 'dateActivate' => $this->dateActivate, 'status' => $this->status, 'userId' => $this->userId]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
/** * Finds the Request model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Request the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Request::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel app\modules\discount\models\RequestSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Заявки'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="request-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'username', ['attribute' => 'cityId', 'value' => 'city.title', 'filter' => \app\modules\cms\models\City::dropDown()], 'email:email', 'phone', ['attribute' => 'status', 'value' => 'statusText', 'filter' => \app\modules\discount\models\Request::getStatusList()], 'dateCreate:date', 'dateActivate:date', ['class' => 'yii\\grid\\ActionColumn', 'buttons' => ['accept' => function ($url, $model) { return Html::a('<i class="fa fa-users"></i>', $url, ['class' => 'btn btn-success btn-xs']); }, 'update' => function ($url, $model) { return Html::a('<i class="fa fa-edit"></i>', $url, ['class' => 'btn btn-primary btn-xs']); }, 'reject' => function ($url, $model) { return Html::a('<i class="fa fa-undo"></i>', $url, ['class' => 'btn btn-danger btn-xs']); }], 'template' => '{accept} | {reject} | {view} |{delete}', 'options' => ['class' => 'col-md-1', 'style' => 'width:130px;text-align:center']]]]); ?> </div>
use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model app\modules\discount\models\Request */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="request-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'status')->radioList(\app\modules\discount\models\Request::getStatusList()); ?> <?php echo $form->field($model, 'username')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'cityId')->dropDownList(\app\modules\cms\models\City::dropDown()); ?> <?php echo $form->field($model, 'phone')->textInput(['maxlength' => 255]); ?> <?php