67 lines
3.0 KiB
PHP
67 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace %NAMESPACE%\%WEB_NS%;
|
|
|
|
use Notes\Breadcrumb\Attribute\Method\Breadcrumb;
|
|
use Notes\Route\Attribute\Method\Route;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface,
|
|
Psr\Http\Message\ResponseInterface;
|
|
|
|
use %NAMESPACE%\{Lib, %USE_ENTITY_NS%, %USE_FORM_NS%, };
|
|
|
|
use function %NAMESPACE%\View\{_, lang, url, route, form};
|
|
|
|
#[\Notes\Route\Attribute\Object\Route(base:"%WEB_ROUTE_BASE%/%CLASSNAME_LC%")]
|
|
class %CLASSNAME% {
|
|
use Lib\ControllerTrait;
|
|
|
|
#[Route("/", name: "%CLASSNAME_LC%:index")]
|
|
##[Breadcrumb(parent: "", icon: "", lang: "app.lang.breadcrumb")]
|
|
public function index(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
|
{
|
|
$search = %ENTITY_NS%\%CLASSNAME%::searchRequest()->fromRequest($request) ;
|
|
$list = %ENTITY_NS%\%CLASSNAME%::repository()->filterServerRequest($search)->loadAll();
|
|
|
|
return $this->renderView('%CLASSNAME_LC%/index', get_defined_vars());
|
|
}
|
|
|
|
#[Route("/create", name: "%CLASSNAME_LC%:create", method: ["GET", "POST"])]
|
|
##[Breadcrumb(parent: "%CLASSNAME_LC%:index", icon: "", lang: "app.lang.breadcrumb")]
|
|
public function create(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
|
{
|
|
$entity = new %ENTITY_NS%\%CLASSNAME%();
|
|
|
|
form($this->formFactory->%SAVE_FORM_CLASSNAME_LC%($entity), $this->pushContext($this->formFactory->%SAVE_FORM_CONTEXT_CLASSNAME_LC%($request, "%CLASSNAME_LC%.create")));
|
|
|
|
if ($entity->isLoaded()) {
|
|
return $this->redirect(route("%CLASSNAME_LC%:edit", [ 'id' => $entity->id ]) );
|
|
}
|
|
|
|
return $this->renderView('%CLASSNAME_LC%/create', get_defined_vars());
|
|
}
|
|
|
|
#[Route("/{id:\d+}/edit", name: "%CLASSNAME_LC%:edit", method: ["GET", "POST"])]
|
|
##[Breadcrumb(parent: "%CLASSNAME_LC%:index", icon: "", lang: "app.lang.breadcrumb")]
|
|
public function edit(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
|
{
|
|
$search = %ENTITY_NS%\%CLASSNAME%::searchRequest()->fromRequest($request);
|
|
$entity = %ENTITY_NS%\%CLASSNAME%::repository()->filterServerRequest($search)->loadOne();
|
|
|
|
form($this->formFactory->%SAVE_FORM_CLASSNAME_LC%($entity), $this->pushContext($this->formFactory->%SAVE_FORM_CONTEXT_CLASSNAME_LC%($request, "%CLASSNAME_LC%.edit")));
|
|
|
|
return $this->renderView('%CLASSNAME_LC%/edit', get_defined_vars());
|
|
}
|
|
|
|
#[Route("/{id:\d+}/delete", name: "%CLASSNAME_LC%:delete", method: ["POST", "DELETE"])]
|
|
public function delete(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
|
{
|
|
$search = %ENTITY_NS%\%CLASSNAME%::searchRequest()->fromRequest($request);
|
|
$entity = %ENTITY_NS%\%CLASSNAME%::repository()->filterServerRequest($search)->loadOne();
|
|
|
|
form($this->formFactory->%DELETE_FORM_CLASSNAME_LC%($entity), $this->pushContext($this->formFactory->%DELETE_FORM_CONTEXT_CLASSNAME_LC%($request, "%CLASSNAME_LC%.delete")));
|
|
|
|
return $this->redirect(route("%CLASSNAME_LC%:index"));
|
|
}
|
|
}
|