rest to menu
This commit is contained in:
parent
a3f7a90e39
commit
4c75c9469b
@ -27,6 +27,15 @@ class CgRouteCollector extends RouteCollector
|
||||
return $this->addRoute(Route::ANY, $route . '/update/{id}', array_merge($handler, ['actionEdit']), $filters);
|
||||
}
|
||||
|
||||
public function rest($route, $handler, array $filters = []): CgRouteCollector
|
||||
{
|
||||
$this->addRoute(Route::GET, $route, array_merge($handler, ['actionIndex']), $filters);
|
||||
$this->addRoute(Route::GET, $route . '/{id}', array_merge($handler, ['actionView']), $filters);
|
||||
$this->addRoute(Route::POST, $route . '/', array_merge($handler, ['actionStore']), $filters);
|
||||
$this->addRoute(Route::DELETE, $route . '/delete', array_merge($handler, ['actionDelete']), $filters);
|
||||
return $this->addRoute(Route::ANY, $route . '/update/{id}', array_merge($handler, ['actionEdit']), $filters);
|
||||
}
|
||||
|
||||
public function authorization($route, $handler, array $filters = [])
|
||||
{
|
||||
//TODO
|
||||
|
@ -74,17 +74,17 @@ class RestController
|
||||
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionCreate(): void
|
||||
#[NoReturn] public function actionStore(): void
|
||||
{
|
||||
|
||||
$request = new Request();
|
||||
$data = $request->post();
|
||||
$data = [
|
||||
'title' => 'title'
|
||||
];
|
||||
Debug::prn($data);
|
||||
$model = $this->model;
|
||||
Debug::prn($model->toArray());
|
||||
$model->save($data);
|
||||
foreach ($this->model->getFillable() as $item){
|
||||
$this->model->{$item} = $data[$item] ?? null;
|
||||
}
|
||||
$this->model->save();
|
||||
|
||||
$this->renderApi($this->model->toArray());
|
||||
}
|
||||
|
||||
#[NoReturn] protected function renderApi(array $data): void
|
||||
|
16
kernel/modules/menu/controllers/MenuRestController.php
Normal file
16
kernel/modules/menu/controllers/MenuRestController.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\modules\menu\controllers;
|
||||
|
||||
use kernel\modules\menu\models\Menu;
|
||||
use kernel\RestController;
|
||||
|
||||
class MenuRestController extends RestController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new Menu();
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use kernel\App;
|
||||
use kernel\CgRouteCollector;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router) {
|
||||
@ -17,3 +18,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router)
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
|
||||
$router->rest("menu", [\kernel\modules\menu\controllers\MenuRestController::class]);
|
||||
});
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use kernel\App;
|
||||
use kernel\CgRouteCollector;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
|
||||
@ -17,16 +18,6 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
});
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "api"], function (RouteCollector $router){
|
||||
App::$collector->group(["prefix" => "post"], function (RouteCollector $router){
|
||||
App::$collector->get('/', [\kernel\modules\post\controllers\PostRestController::class, 'actionIndex']);
|
||||
App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostRestController::class, 'actionView']);
|
||||
// App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
|
||||
App::$collector->post('/create', [\kernel\modules\post\controllers\PostRestController::class, 'actionCreate']);
|
||||
// App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']);
|
||||
// App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']);
|
||||
// App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']);
|
||||
// App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostRestController::class, 'actionDelete']);
|
||||
});
|
||||
App::$collector->group(["prefix" => "api"], function (CgRouteCollector $router){
|
||||
$router->rest("post", [\kernel\modules\post\controllers\PostRestController::class]);
|
||||
});
|
Loading…
Reference in New Issue
Block a user