flash, middleware
This commit is contained in:
@ -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/");
|
||||
}
|
||||
|
@ -5,14 +5,11 @@
|
||||
* @var int $page_number
|
||||
*/
|
||||
|
||||
use kernel\IGTabel\action_column\DeleteActionColumn;
|
||||
use kernel\IGTabel\action_column\EditActionColumn;
|
||||
use kernel\IGTabel\action_column\ViewActionColumn;
|
||||
use kernel\modules\post\models\Post;
|
||||
use kernel\modules\post\table\columns\PostDeleteActionColumn;
|
||||
use kernel\modules\post\table\columns\PostEditActionColumn;
|
||||
use kernel\modules\post\table\columns\PostViewActionColumn;
|
||||
use kernel\modules\user\models\User;
|
||||
//use app\tables\columns\post\PostDeleteActionColumn;
|
||||
//use app\tables\columns\post\PostEditActionColumn;
|
||||
//use app\tables\columns\post\PostViewActionColumn;
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
@ -46,8 +43,8 @@ $table->beforePrint(function () {
|
||||
return PrimaryBtn::create("Создать", "/admin/post/create")->fetch();
|
||||
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
|
||||
});
|
||||
$table->addAction(PostViewActionColumn::class);
|
||||
$table->addAction(PostEditActionColumn::class);
|
||||
$table->addAction(PostDeleteActionColumn::class);
|
||||
$table->addAction(ViewActionColumn::class);
|
||||
$table->addAction(EditActionColumn::class);
|
||||
$table->addAction(DeleteActionColumn::class);
|
||||
$table->create();
|
||||
$table->render();
|
Reference in New Issue
Block a user