/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = AuthAssignment::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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; } $query->andFilterWhere(['created_at' => $this->created_at]); $query->andFilterWhere(['like', 'item_name', $this->item_name])->andFilterWhere(['like', 'user_id', $this->user_id]); return $dataProvider; }
<?php echo $this->render('_form', ['model' => $model]); ?> <!-- <table> <tr> <td style="margin: 5px;"> <?php echo Html::tag('p', 'Назначенные роли'); $assignment = []; foreach ($roles as $item) { $assignment[] = $item->item_name; } echo Html::listBox('roles', null, $assignment); ?> </td> <td style="margin: 5px;"> <?php echo Html::tag('p', 'Доступные роли'); $auth = AuthAssignment::find()->all(); $assignment = []; foreach ($auth as $item) { $assignment[] = $item->item_name; } echo Html::listBox('roles', null, $assignment); ?> </td> </tr> </table>--> </div>
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { /* * Asign auth_assignment for current user */ $array = ArrayHelper::map(\backend\models\AuthAssignment::find()->where(['user_id' => $id])->all(), 'user_id', 'item_name'); if ($array) { $model->auth_assignment = $array[$id]; } return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }