Convert HubController to use Menu annotation instead of base controller #222

This commit is contained in:
Kendrick Chan 2019-06-07 02:03:30 +08:00
parent 915cb6ba8d
commit 3d1a1c3173
2 changed files with 16 additions and 9 deletions

View file

@ -130,4 +130,3 @@ services:
$menu_name: "main_menu"
tags:
- { name: kernel.event_listener, event: kernel.controller, method: onKernelController }

View file

@ -11,19 +11,24 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
use DateTime;
use Catalyst\MenuBundle\Annotation\Menu;
class HubController extends BaseController
{
/**
* @Menu(selected="hub_list")
*/
public function index()
{
$this->denyAccessUnlessGranted('hub.list', null, 'No access.');
$params = $this->initParameters('hub_list');
return $this->render('hub/list.html.twig', $params);
return $this->render('hub/list.html.twig');
}
public function rows(Request $req)
@ -112,11 +117,14 @@ class HubController extends BaseController
]);
}
/**
* @Menu(selected="hub_list")
*/
public function addForm()
{
$this->denyAccessUnlessGranted('hub.add', null, 'No access.');
$params = $this->initParameters('hub_list');
$params = [];
$params['obj'] = new Hub();
$params['mode'] = 'create';
@ -195,12 +203,13 @@ class HubController extends BaseController
]);
}
/**
* @Menu(selected="hub_list")
*/
public function updateForm($id)
{
$this->denyAccessUnlessGranted('hub.update', null, 'No access.');
$params = $this->initParameters('hub_list');
// get row data
$em = $this->getDoctrine()->getManager();
$obj = $em->getRepository(Hub::class)->find($id);
@ -209,6 +218,7 @@ class HubController extends BaseController
if (empty($obj))
throw $this->createNotFoundException('The item does not exist');
$params = [];
$params['obj'] = $obj;
$params['mode'] = 'update';
@ -263,8 +273,6 @@ class HubController extends BaseController
{
$this->denyAccessUnlessGranted('hub.delete', null, 'No access.');
$params = $this->initParameters('hub_list');
// get objext data
$em = $this->getDoctrine()->getManager();
$obj = $em->getRepository(Hub::class)->find($id);