шаг 4 завершен
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Repositories\CategoryRepository;
|
||||
|
||||
final class CategoryAdminController
|
||||
{
|
||||
public function index(): void
|
||||
{
|
||||
$repository = new CategoryRepository();
|
||||
$message = null;
|
||||
$error = null;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
try {
|
||||
$repository->create([
|
||||
'parent_id' => $_POST['parent_id'] !== '' ? (int) $_POST['parent_id'] : null,
|
||||
'name' => trim((string) $_POST['name']),
|
||||
'slug' => trim((string) $_POST['slug']),
|
||||
'h1' => trim((string) ($_POST['h1'] ?? '')),
|
||||
'seo_title' => trim((string) ($_POST['seo_title'] ?? '')),
|
||||
'seo_description' => trim((string) ($_POST['seo_description'] ?? '')),
|
||||
'seo_keywords' => trim((string) ($_POST['seo_keywords'] ?? '')),
|
||||
'sort_order' => (int) ($_POST['sort_order'] ?? 100),
|
||||
'is_active' => isset($_POST['is_active']) ? 1 : 0,
|
||||
]);
|
||||
$message = 'Категория добавлена.';
|
||||
} catch (\Throwable $exception) {
|
||||
$error = app_env('APP_DEBUG', 'false') === 'true' ? $exception->getMessage() : 'Не удалось добавить категорию.';
|
||||
}
|
||||
}
|
||||
|
||||
view('admin/categories', [
|
||||
'title' => 'Категории - админка Рыбсток',
|
||||
'breadcrumbs' => [
|
||||
['title' => 'Главная', 'url' => '/'],
|
||||
['title' => 'Админка', 'url' => '/admin/'],
|
||||
['title' => 'Категории'],
|
||||
],
|
||||
'categories' => $repository->tree(),
|
||||
'flatCategories' => $repository->flatActive(),
|
||||
'message' => $message,
|
||||
'error' => $error,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user