'app/views/cache']); echo $this->twig->render('userCreate.html'); } public function actionAdd(): void { $_REQUEST["password_hash"] = password_hash($_REQUEST["password_hash"], PASSWORD_DEFAULT); User::create($_REQUEST); } public function actionQuestionCount($user_id) { return Question::where('user_id', $user_id)->count(); } /** * @throws \Exception */ public function actionIndex(): void { $users = User::where(['role' => 1])->get(); $this->twig->addFunction(new TwigFunction('table', function () use ($users){ $dataProvider = new ListJsonTableEloquentCollection($users, [ 'model' => User::class, 'perPage' => 5, 'params' => ["class" => "table table-bordered", "border" => "2"], 'baseUrl' => "/admin/user", ]); $table = new ListJsonTable($dataProvider->getJson()); $table->addAction(UserViewActionColumn::class); $table->create(); $table->render(); })); echo $this->twig->render('user_table.html.twig'); } public function actionView($id): void { echo User::where('id', '=', $id)->get(); echo User::where('id', '=', $id)->first() . "

"; $user = User::find($id); echo $user->id . "
"; echo $user->username . "
"; echo $user->email . "
"; echo $user->created_at . "
"; echo $user->updated_at . "
"; } public function actionUpdate(): void { // $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views'); // $twig = new \Twig\Environment($loader, ['cache' => 'app/views/cache']); echo $this->twig->render('userUpdate.html'); } public function actionEdit(): void { $_REQUEST["password_hash"] = password_hash($_REQUEST["password_hash"], PASSWORD_DEFAULT); $user = User::find($_REQUEST['id']); $user->username = $_REQUEST['username']; $user->email = $_REQUEST['email']; $user->password_hash = $_REQUEST['password_hash']; $user->save(); } public function actionDelete($id): void { User::find($id)->delete(); } }