[ 'class' => \yii\filters\AccessControl::className(), 'rules' => [ // allow authenticated users [ 'actions' => ['create','index','view','update','list'], 'allow' => true, 'roles' => ['@'], ], // everything else is denied ], ], ]; } /** * Lists all Card models. * @return mixed */ public function actionIndex() { $searchModel = new CardSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } /** * Displays a single Card model. * @param integer $id * @return mixed */ public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } /** * Creates a new Card model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Card(); $model->status = Card::STATUS_ACTIVE; $model->type = Card::TYPE_RFID; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id_card]); } else { return $this->render('create', [ 'model' => $model, ]); } } /** * Updates an existing Card model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id_card]); } else { return $this->render('update', [ 'model' => $model, ]); } } /** * Deletes an existing Card model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } /** * Finds the Card model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Card the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Card::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /** * Your controller action to fetch the list */ public function actionList($search = null) { $query = new Query(); $query->select ( [ 'card.number as number', 'customer.name as name', "concat( card.number , case when customer.name is null then '' else customer.name end ) as txt ", ] )->from (Card::tableName() )->join("left join", Customer::tableName(), 'card.id_card = customer.id_customer_card')->where ( ' lower(number) LIKE "%' . strtolower ( $search ) . '%"' )->orderBy ( 'number' ) ; if ( isset($_GET['onlyFree']) && $_GET['onlyFree'] == '1'){ $query->andWhere( 'customer.id_customer is null' ); } $command = $query->createCommand (); $data = $command->queryAll (); $out = [ ]; foreach ( $data as $d ) { $out [] = [ 'number' => $d ['number'], 'name' => $d ['name'], 'txt' => $d ['txt'], ]; } echo Json::encode ( $out ); } }