crud menu
This commit is contained in:
106
app/controllers/MenuController.php
Normal file
106
app/controllers/MenuController.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use app\helpers\Debug;
|
||||
use app\models\forms\CreateMenuForm;
|
||||
use app\services\MenuService;
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\Controller;
|
||||
use kernel\models\Menu;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
|
||||
class MenuController extends Controller
|
||||
{
|
||||
protected function init(): void
|
||||
{
|
||||
$this->cgView->viewPath = ROOT_DIR . "/views/admin/";
|
||||
$this->cgView->layout = "layouts/main.php";
|
||||
}
|
||||
|
||||
public function actionCreate(): void
|
||||
{
|
||||
$this->cgView->render("menu/form.php");
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionAdd(): void
|
||||
{
|
||||
$menuForm = new CreateMenuForm();
|
||||
$menuService = new MenuService();
|
||||
$menuForm->load($_REQUEST);
|
||||
if ($menuForm->validate()){
|
||||
$menuItem = $menuService->create($menuForm);
|
||||
if ($menuItem){
|
||||
$this->redirect("/admin/menu/" . $menuItem->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/menu/create");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionIndex($page_number = 1): void
|
||||
{
|
||||
$this->cgView->render("menu/index.php", ['page_number' => $page_number]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionView($id): void
|
||||
{
|
||||
$menuItem = Menu::find($id);
|
||||
|
||||
if (!$menuItem){
|
||||
throw new Exception(message: "The menu item not found");
|
||||
}
|
||||
$this->cgView->render("menu/view.php", ['menu' => $menuItem]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeError
|
||||
* @throws SyntaxError
|
||||
* @throws LoaderError|Exception
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$model = Menu::find($id);
|
||||
if (!$model){
|
||||
throw new Exception(message: "The menu item not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("menu/form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$menuItem = Menu::find($id);
|
||||
if (!$menuItem){
|
||||
throw new Exception(message: "The menu item not found");
|
||||
}
|
||||
$menuForm = new CreateMenuForm();
|
||||
$menuService = new MenuService();
|
||||
$menuForm->load($_REQUEST);
|
||||
if ($menuForm->validate()){
|
||||
$menuItem = $menuService->update($menuForm, $menuItem);
|
||||
if ($menuItem){
|
||||
$this->redirect("/admin/menu/" . $menuItem->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/menu/update/" . $id);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete($id): void
|
||||
{
|
||||
Menu::find($id)->delete();
|
||||
$this->redirect("/admin/menu/");
|
||||
}
|
||||
|
||||
}
|
@ -30,16 +30,10 @@ class PostController extends Controller
|
||||
$postForm = new CreatePostForm();
|
||||
$postService = new PostService();
|
||||
$postForm->load($_REQUEST);
|
||||
// Debug::dd($_REQUEST);
|
||||
if(UserService::check($_REQUEST['user_id'])) {
|
||||
// Debug::dd(123);
|
||||
if ($postForm->validate()) {
|
||||
|
||||
// Debug::dd($postForm);
|
||||
$post = $postService->create($postForm);
|
||||
if ($post) {
|
||||
$this->redirect("/admin/post/" . $post->id);
|
||||
}
|
||||
if ($postForm->validate()) {
|
||||
$post = $postService->create($postForm);
|
||||
if ($post) {
|
||||
$this->redirect("/admin/post/" . $post->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/post/create");
|
||||
@ -49,11 +43,9 @@ class PostController extends Controller
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public function actionIndex(): void
|
||||
public function actionIndex($page_number = 1): void
|
||||
{
|
||||
$contents = Post::all();
|
||||
|
||||
$this->cgView->render("post/index.php", ['contents' => $contents]);
|
||||
$this->cgView->render("post/index.php", ['page_number' => $page_number]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,31 +2,16 @@
|
||||
namespace app\controllers;
|
||||
|
||||
|
||||
use app\foo;
|
||||
use app\helpers\Debug;
|
||||
use app\models\forms\CreateUserForm;
|
||||
use app\models\Question;
|
||||
use app\models\User;
|
||||
use app\services\UserService;
|
||||
use app\tables\columns\UserEditActionColumn;
|
||||
use app\tables\columns\UserViewActionColumn;
|
||||
use Exception;
|
||||
use http\Message;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Itguild\Tables\ListJsonTable;
|
||||
use Itguild\Tables\ViewJsonTable;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\App;
|
||||
use kernel\Controller;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\IGTabel\EloquentDataProvider;
|
||||
use kernel\IGTabel\ListJsonTableEloquentCollection;
|
||||
use kernel\IGTabel\ViewJsonTableEloquentModel;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class UserController extends Controller{
|
||||
protected function init(): void
|
||||
|
Reference in New Issue
Block a user