create beta

This commit is contained in:
Билай Станислав 2024-07-24 12:50:07 +03:00
parent 910bf56766
commit 094e047a5c

View File

@ -19,15 +19,28 @@ use Twig\TwigFunction;
class UserController extends Controller{ class UserController extends Controller{
public function actionCreate(): void public function actionCreate(): void
{ {
// $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../views');
// $twig = new \Twig\Environment($loader, ['cache' => 'app/views/cache']);
echo $this->twig->render('user_create.html.twig'); echo $this->twig->render('user_create.html.twig');
} }
public function actionAdd(): void public function actionAdd(): void
{ {
$_REQUEST["password_hash"] = password_hash($_REQUEST["password_hash"], PASSWORD_DEFAULT); $_REQUEST["password_hash"] = password_hash($_REQUEST["password_hash"], PASSWORD_DEFAULT);
User::create($_REQUEST);
foreach ($_REQUEST as $key => $value)
{
// Debug::prn(User::where([$key => $value])->get()->toArray());
// Debug::prn($user);
// Debug::dd($user->toArray());
if (User::where([$key => $value])->get()->toArray() !== null)
{
header("Location: http://itguild-framework.loc/admin/user/create");
}
else
{
User::create($_REQUEST);
header("Location: http://itguild-framework.loc/admin/user/");
}
}
} }
public function actionQuestionCount($user_id) public function actionQuestionCount($user_id)
@ -64,6 +77,7 @@ class UserController extends Controller{
public function actionView($id): void public function actionView($id): void
{ {
$user = User::find($id); $user = User::find($id);
if (!$user){ if (!$user){
throw new Exception(message: "The user not found"); throw new Exception(message: "The user not found");
} }