Example #1
0
 /**
  * @param \yii\base\Action $action
  *
  * @return bool
  */
 public function beforeAction($action)
 {
     $request = \Yii::$app->request;
     if (!$request->get('device_id')) {
         return false;
     }
     /** @noinspection PhpUndefinedFieldInspection */
     $action->controller->device = Device::findOne($request->get('device_id'));
     return parent::beforeAction($action);
 }
Example #2
0
 public function validateAttribute($model, $attribute)
 {
     $value = $model->{$attribute};
     if (isset($model->id) || isset($model->item_id)) {
         /** @noinspection PhpUndefinedFieldInspection */
         $modelId = isset($model->id) ? $model->id : $model->item_id;
         if (Device::find()->where(['!=', 'id', $modelId])->andWhere(['text_id' => $value])->exists()) {
             $model->addError($attribute, $this->message);
         }
     } else {
         if (Device::find()->where(['text_id' => $value])->exists()) {
             $model->addError($attribute, $this->message);
         }
     }
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  * @param $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = parent::find();
     if (!isset($params['sort'])) {
         $query->orderBy(['title' => SORT_ASC]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['like', 'title', $this->title]);
     $query->andFilterWhere(['like', 'text_id', $this->text_id]);
     return $dataProvider;
 }
Example #4
0
 public function __construct($config)
 {
     $this->modelClass = Device::className();
     parent::__construct($config);
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDevice()
 {
     return $this->hasOne(Device::className(), ['id' => 'device_id']);
 }
Example #6
0
 public function init()
 {
     parent::init();
     $this->_items = Device::find()->where(['like', 'text_id', $this->keyword])->all();
 }
Example #7
0
 public function __construct($config)
 {
     parent::__construct();
     $this->device = Device::findOne($config['device_id']);
 }
Example #8
0
 /**
  * Finds the model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Device the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Device::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }