module shop crud

This commit is contained in:
2024-10-16 16:06:25 +03:00
parent b7ac923261
commit 209b1e3f29
15 changed files with 414 additions and 22 deletions

View File

@ -42,7 +42,7 @@ class PostController extends AdminController
* @throws Exception
*/
public function actionIndex($page_number = 1): void
public function actionIndex(int $page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
@ -50,7 +50,7 @@ class PostController extends AdminController
/**
* @throws Exception
*/
public function actionView($id): void
public function actionView(int $id): void
{
$content = Post::find($id);
@ -63,7 +63,7 @@ class PostController extends AdminController
/**
* @throws Exception
*/
public function actionUpdate($id): void
public function actionUpdate(int $id): void
{
$model = Post::find($id);
if (!$model){
@ -76,17 +76,16 @@ class PostController extends AdminController
/**
* @throws Exception
*/
public function actionEdit($id): void
public function actionEdit(int $id): void
{
$post = Post::find($id);
if (!$post){
throw new Exception(message: "The post not found");
}
$postForm = new CreatePostForm();
$postService = new PostService();
$postForm->load($_REQUEST);
if ($postForm->validate()) {
$post = $postService->update($postForm, $post);
$post = $this->postService->update($postForm, $post);
if ($post) {
$this->redirect("/admin/post/" . $post->id);
}
@ -94,9 +93,15 @@ class PostController extends AdminController
$this->redirect("/admin/post/update/" . $id);
}
#[NoReturn] public function actionDelete($id): void
/**
* @throws Exception
*/
#[NoReturn] public function actionDelete(int $id): void
{
$post = Post::find($id)->first();
if (!$post){
throw new Exception(message: "The post not found");
}
$post->delete();
$this->redirect("/admin/post/");
}