0

My root url is http://restaurent.local i want to route like this http://restaurent.local/menuedit/test/1. But this not working This is my code

     'menuedit' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/menuedit[/:action][/:id]',
                'defaults' => array(
                    'controller' => 'Menu\Controller\Menu',
                    'action'     => 'menuedit',
                ),
            ),
        ),

if any one know about this please help me.

doydoy44
  • 5,720
  • 4
  • 29
  • 45
deepu sankar
  • 4,335
  • 3
  • 26
  • 37

3 Answers3

0

You're attempting to use a Literal route type. You need a Segment route type if you want to match your route parameters ...

 'menuedit' => array(
        'type' => 'Zend\Mvc\Router\Http\Segment',
        'options' => array(
            'route'    => '/menuedit[/:action][/:id]',
            'defaults' => array(
                'controller' => 'Menu\Controller\Menu',
                'action'     => 'menuedit',
            ),
        ),
    ),

Please consider reading the manual to understand the differences and how they're meant to be used -> http://framework.zend.com/manual/2.3/en/modules/zend.mvc.routing.html#http-route-types

Crisp
  • 11,417
  • 3
  • 38
  • 41
0

You might also want to set your constraints for the route parameters. I'd also make the trailing backslash optional with [/] otherwise it won't match /route/to/ it would only match /route/to

'menuedit' => array(
    'type' => 'segment',
    'options' => array(
        'route'    => '/menuedit[/][:action][/:id]',
        'constraints' => array(
            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
            'id'     => [0-9]*'
         ),
        'defaults' => array(
            'controller' => 'Menu\Controller\Menu',
            'action'     => 'menuedit',
        ),
    ),
),
alex
  • 602
  • 4
  • 7
0

I Literal route can't handle params.

'type' => 'Zend\Mvc\Router\Http\Literal',

You want to edit a specific menu, with specific id, this is a param.

For handle param you have to use Segment type.

Don't forget to add constraints option for your action AND your id. More secure.

Greco Jonathan
  • 2,517
  • 2
  • 29
  • 54