public function actionView($key) { $model = Order::findBySecretKey($key); if (!$model) { throw new HttpException('404', 'Заказ не найден'); } return $this->render('view', ['model' => $model]); }
/** * Finds the Order model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Order the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Order::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 = Order::find(); $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 any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'dateCreate' => $this->dateCreate, 'statusId' => $this->statusId]); $query->andFilterWhere(['like', 'fio', $this->fio])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'secretKey', $this->secretKey]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel app\modules\store\models\OrderSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Заказ'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="order-index"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'statusId', 'value' => 'statusTitle', 'filter' => \app\modules\store\models\Order::statusList()], 'fio', 'phone', 'email:email', 'dateCreate', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update}']]]); ?> </div>
use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model app\modules\store\models\Order */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="order-form"> <div class="row"> <div class="col-md-6"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'statusId')->dropDownList(\app\modules\store\models\Order::statusList()); ?> <?php echo $form->field($model, 'fio')->textInput(['maxlength' => 128, 'readonly' => true]); ?> <?php echo $form->field($model, 'phone')->textInput(['maxlength' => 23, 'readonly' => true]); ?> <?php echo $form->field($model, 'email')->textInput(['maxlength' => 64, 'readonly' => true]); ?> <?php