update beta
This commit is contained in:
parent
043a699c6d
commit
0e13d2c418
@ -8,6 +8,7 @@ use app\models\forms\CreateUserForm;
|
|||||||
use app\models\Question;
|
use app\models\Question;
|
||||||
use app\models\User;
|
use app\models\User;
|
||||||
use app\services\UserService;
|
use app\services\UserService;
|
||||||
|
use app\tables\columns\UserEditActionColumn;
|
||||||
use app\tables\columns\UserViewActionColumn;
|
use app\tables\columns\UserViewActionColumn;
|
||||||
use Exception;
|
use Exception;
|
||||||
use http\Message;
|
use http\Message;
|
||||||
@ -29,11 +30,19 @@ class UserController extends Controller{
|
|||||||
$userForm = new CreateUserForm();
|
$userForm = new CreateUserForm();
|
||||||
$userService = new UserService();
|
$userService = new UserService();
|
||||||
$userForm->load($_REQUEST);
|
$userForm->load($_REQUEST);
|
||||||
|
// Debug::prn($userForm->validate());
|
||||||
|
// Debug::dd($userForm->getErrors());
|
||||||
if ($userForm->validate()){
|
if ($userForm->validate()){
|
||||||
|
// Debug::prn($userService);
|
||||||
|
|
||||||
$userService->create($userForm);
|
$userService->create($userForm);
|
||||||
$this->redirect("/admin/user");
|
// Debug::dd($userService->create($userForm));
|
||||||
|
$this->redirect("/admin/user/" . User::latest()->first()['id']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->redirect("/admin/user/create");
|
||||||
}
|
}
|
||||||
$this->redirect("/admin/user/create");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionQuestionCount($user_id)
|
public function actionQuestionCount($user_id)
|
||||||
@ -57,6 +66,7 @@ class UserController extends Controller{
|
|||||||
]);
|
]);
|
||||||
$table = new ListJsonTable($dataProvider->getJson());
|
$table = new ListJsonTable($dataProvider->getJson());
|
||||||
$table->addAction(UserViewActionColumn::class);
|
$table->addAction(UserViewActionColumn::class);
|
||||||
|
$table->addAction(UserEditActionColumn::class);
|
||||||
$table->create();
|
$table->create();
|
||||||
$table->render();
|
$table->render();
|
||||||
}));
|
}));
|
||||||
@ -87,22 +97,40 @@ class UserController extends Controller{
|
|||||||
echo $this->twig->render('user_table.html.twig');
|
echo $this->twig->render('user_table.html.twig');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionUpdate(): void
|
public function actionUpdate($id): void
|
||||||
{
|
{
|
||||||
// $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views');
|
|
||||||
// $twig = new \Twig\Environment($loader, ['cache' => 'app/views/cache']);
|
|
||||||
echo $this->twig->render('user_update.html.twig');
|
echo $this->twig->render('user_update.html.twig');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionEdit(): void
|
public function actionEdit($id): void
|
||||||
{
|
{
|
||||||
$_REQUEST["password_hash"] = password_hash($_REQUEST["password_hash"], PASSWORD_DEFAULT);
|
// $_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();
|
||||||
|
|
||||||
$user = User::find($_REQUEST['id']);
|
// $user = User::find($id);
|
||||||
$user->username = $_REQUEST['username'];
|
// if (!$user){
|
||||||
$user->email = $_REQUEST['email'];
|
// throw new Exception(message: "The user not found");
|
||||||
$user->password_hash = $_REQUEST['password_hash'];
|
// }
|
||||||
$user->save();
|
// $userForm = new CreateUserForm();
|
||||||
|
// $userService = new UserService();
|
||||||
|
// $userForm->load($_REQUEST);
|
||||||
|
//// Debug::prn($userForm->validate());
|
||||||
|
//// Debug::dd($userForm->getErrors());
|
||||||
|
// if ($userForm->validate()){
|
||||||
|
//// Debug::prn($userService);
|
||||||
|
//
|
||||||
|
// $userService->create($userForm);
|
||||||
|
// $this->redirect("/admin/user/" . User::find($id)['id']);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// $this->redirect("/admin/user/update/" . $id);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionDelete($id): void
|
public function actionDelete($id): void
|
||||||
|
17
app/tables/columns/UserEditActionColumn.php
Normal file
17
app/tables/columns/UserEditActionColumn.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\tables\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class UserEditActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
// $link = $this->baseUrl . $this->prefix . $this->id . $this->prefix . "update";
|
||||||
|
$link = $this->baseUrl . $this->prefix . "update" . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-primary'>Редактировать</a> ";
|
||||||
|
}
|
||||||
|
}
|
11
index.php
11
index.php
@ -19,13 +19,14 @@ $router->get('/', [MainController::class, 'actionIndex']);
|
|||||||
$router->get('/example', [MainController::class, 'actionExample']);
|
$router->get('/example', [MainController::class, 'actionExample']);
|
||||||
$router->group(["prefix" => "admin"], function (RouteCollector $router){
|
$router->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||||
$router->group(["prefix" => "user"], function (RouteCollector $router){
|
$router->group(["prefix" => "user"], function (RouteCollector $router){
|
||||||
$router->get('/create', [\app\controllers\UserController::class, 'actionCreate']);
|
|
||||||
$router->get('/update', [\app\controllers\UserController::class, 'actionUpdate']);
|
|
||||||
$router->get('/delete/{id}', [\app\controllers\UserController::class, 'actionDelete']);
|
|
||||||
$router->get('/', [\app\controllers\UserController::class, 'actionIndex']);
|
$router->get('/', [\app\controllers\UserController::class, 'actionIndex']);
|
||||||
$router->get('/{id}', [\app\controllers\UserController::class, 'actionView']);
|
$router->get('/create', [\app\controllers\UserController::class, 'actionCreate']);
|
||||||
$router->post("/", [\app\controllers\UserController::class, 'actionAdd']);
|
$router->post("/", [\app\controllers\UserController::class, 'actionAdd']);
|
||||||
$router->post("/edit", [\app\controllers\UserController::class, 'actionEdit']);
|
$router->get('/{id}', [\app\controllers\UserController::class, 'actionView']);
|
||||||
|
// $router->get('/{id}/update', [\app\controllers\UserController::class, 'actionUpdate']);
|
||||||
|
$router->any('/update/{id}', [\app\controllers\UserController::class, 'actionUpdate']);
|
||||||
|
$router->any("/edit/{id}", [\app\controllers\UserController::class, 'actionEdit']);
|
||||||
|
$router->get('/delete/{id}', [\app\controllers\UserController::class, 'actionDelete']);
|
||||||
});
|
});
|
||||||
$router->group(["prefix" => "question"], function (RouteCollector $router){
|
$router->group(["prefix" => "question"], function (RouteCollector $router){
|
||||||
$router->get('/create', [QuestionController::class, 'actionCreate']);
|
$router->get('/create', [QuestionController::class, 'actionCreate']);
|
||||||
|
@ -2,11 +2,6 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form action="/admin/user/edit" method="post">
|
<form action="/admin/user/edit" method="post">
|
||||||
id пользователя:<br>
|
|
||||||
<label>
|
|
||||||
<input type = "text" name = "id" required size="50" autofocus placeholder="id">
|
|
||||||
</label> <br> <br>
|
|
||||||
|
|
||||||
Логин:<br>
|
Логин:<br>
|
||||||
<label>
|
<label>
|
||||||
<input type = "text" name = "username" required size="50" autofocus placeholder="Логин">
|
<input type = "text" name = "username" required size="50" autofocus placeholder="Логин">
|
||||||
@ -14,12 +9,12 @@
|
|||||||
|
|
||||||
Пароль:<br>
|
Пароль:<br>
|
||||||
<label>
|
<label>
|
||||||
<input type = "text" name = "password_hash" required size="50" placeholder="Пароль">
|
<input type = "text" name = "password" placeholder="Пароль">
|
||||||
</label> <br> <br>
|
</label> <br> <br>
|
||||||
|
|
||||||
Email адрес: <br>
|
Email адрес: <br>
|
||||||
<label>
|
<label>
|
||||||
<input type="Email" name="email" required>
|
<input type="Email" name="email" required placeholder="Email">
|
||||||
</label> <br><br>
|
</label> <br><br>
|
||||||
|
|
||||||
<input type = "submit" value="Подтвердить">
|
<input type = "submit" value="Подтвердить">
|
||||||
|
Loading…
Reference in New Issue
Block a user