3
votes

Havin in a Zend Module following structure

Name of Module

  • Test
    • config
    • src
    • view
      • layout
      • test
        • index
          • index.phtml
        • login
          • index.phtml
        • register
          • index.phtml
    • Module.php

Now when accessing website for example for login file it will be as following http://justsite.something.com/login

Problem Need to change to http://justsite.something.com/login/ for that i added to login folder another folder index and there putted index.phtml file like this

  • login
    • index
      • index.phtml

But that doesn't seem to work. Should i change in LoginController.php for this to work?

module.confing.php

'router' => array(
    'routes' => array(
        'test' => array(
            'type' => 'Literal',
            'options' => array(
                'route' => '/test',
                'defaults' => array(
                    '__NAMESPACE__' =>'Test\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes'  => array(
                'default' => array(
                    'type' => 'Segment',
                    'options' => array(
                        'route' =>
                        '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' =>
                            '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action' =>
                            '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(),
                    ),
                ),
            ),
        ),
        'login' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/login/', // PUT HERE WHATEVER YOU WANT
                'defaults' => array(  // AND MAP THAT URL TO CONTROLLER/ACTION
                    '__NAMESPACE__' =>'Test\Controller',                    
                    'controller' => 'Login',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),

Fixed Just added

'may_terminate' => true,
            'child_routes'  => array(
                'default' => array(
                    'type' => 'Segment',
                    'options' => array(
                        'route' =>
                        '/[:controller[/:action]/]',
2
Why do you need the path with a slash in the end without any string following? - Wilt
Such are the requirements of a project. - I M

2 Answers

1
votes

Like @tasmaniski wrote you don't need to make changes to LoginController or whatever, all comes down to your route config. You are not the only one who wants "trailing slashes" in his routes, here you can read how you can achieve this.

Apparently you need to put it between []

'route'    => '/[:controller[/[:action[/]]]]',

Hope that solves it for you.

NOTE Some people suggest using a rewrite rule for this, I thought this might be worth mentioning too.

0
votes

No matter what is your forlder structure. You need to make a change in the config file module.config.php, section "routes".

You only need to put in "route" value with slash at the end and map it to controller/action.

'routes' => array(
    'login' => array(
        'type'    => 'Zend\Mvc\Router\Http\Literal',
        'options' => array(
            'route'    => '/login/', // PUT HERE WHATEVER YOU WANT
            'defaults' => array(     // AND MAP THAT URL TO CONTROLLER/ACTION
                'controller' => 'Application\Controller\Login',
                'action'     => 'index',
            ),
        ),
    ),
)