Problem with routing

For programming and general questions on Zend Framework
Post Reply
chri187
Posts: 3
Joined: Fri Jun 05, 2015 10:09 am

Problem with routing

Post by chri187 » Wed Jan 13, 2016 10:30 am

Hi everybody,

I'm starting a new project, with Zend.
Here the problem; Currently, I have two modules:
  • Application
  • Admin
And here (part of) the module.config files for each module:
  • Application

    Code: Select all

     
    namespace Application;
     
    return array(
        'router' =>
        [
            'routes' =>
            [
                'home' =>
                [
                    'type'    => 'Segment',
                    'options' =>
                    [
                        'route'    => '/',
                        'defaults' =>
                        [
                            'controller' => 'application.index',
                            'action'     => 'index',
                        ],
                    ],
                    'may_terminate' => true,
                ],
            ],
        ],
        'controllers' => array(
            'invokables' => array(
                'application.index' => 'Application\Controller\IndexController',
            ),
        ),
        'view_manager' =>
        [
            'display_not_found_reason' => true,
            'display_exceptions'       => true,
            'doctype'                  => 'HTML5',
            'not_found_template'       => 'error/404',
            'exception_template'       => 'error/index',
            'template_map' =>
            [
                'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
                'error/404'     => __DIR__ . '/../view/error/404.phtml',
                'error/index'   => __DIR__ . '/../view/error/index.phtml',
                'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            ],
            'template_path_stack' =>
            [
                __DIR__ . '/../view',
            ],
        ],
    );
    
  • Admin

    Code: Select all

    namespace Admin;
    return [
        'router' =>
        [
            'routes' =>
            [
                'home' =>
                [
     
                    'child_routes' =>
                    [
     
                        'admin' =>
                        [
                            'type'    => 'Segment',
                            'options' =>
                            [
                                'route'    => '/admin',
                                'defaults' =>
                                [
                                    'controller' => 'admin.index',
                                    'action'     => 'index'
                                ],
                            ],
                            'may_terminate' => true,
                            'child_routes'  =>
                            [
                                'post' =>
                                [
                                    'type'    => 'Segment',
                                    'options' =>
                                    [
                                        'route'   => '/post[/:action][/:id]',
                                        'default' =>
                                        [
                                            'controller' => 'admin.post',
                                            'action'     => 'index',
                                        ],
                                        'constraints' =>
                                        [
                                            'action' => 'index|edit|create',
                                            'id'     => '[0-9]+',
                                        ],
                                    ],
                                    'may_terminate' => true,
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
        'controllers' =>
        [
            'invokables' =>
            [
                'admin.index' => 'Admin\Controller\IndexController',
                'admin.post'  => 'Admin\Controller\PostController'
            ],
        ],
        'view_manager' =>
        [
            'display_not_found_reason' => true,
            'display_exceptions'       => true,
            'doctype'                  => 'HTML5',
            'not_found_template'       => 'error/404',
            'exception_template'       => 'error/index',
            'template_map' =>
            [
                'layout/layout'     => __DIR__ . '/../view/layout/layout.phtml',
                'error/404'         => __DIR__ . '/../view/error/404.phtml',
                'error/index'       => __DIR__ . '/../view/error/index.phtml',
            ],
            'template_path_stack' =>
            [
                __DIR__ . '/../../view',
            ],
        ]
    ];
    
The root of my project is defined in my vagrant config, and is local.blog.
And this is where the concerns come:

If I go to the URL local.blog, no problem.
If I go to the URL local.blog/admin, the content displays a 404: "the requested URL Could not be matched by routing.

So I think I missed something in the configuration of routing, but I'm not sure.
Last question: in the layout of the application module, how to link to ADMIN? The link below is not working ..

Code: Select all

<a href="<?php echo $this->url('home/admin'); ?>">
ADMIN
</a>
Thanks for help!

stij2324
Posts: 55
Joined: Fri Nov 06, 2015 11:42 pm

Re: Problem with routing

Post by stij2324 » Wed Feb 03, 2016 11:30 pm

Indead i can see wat is missing but can't typ the correct syntax so you need to look for it.
For you home route you need to add a child route with as name admin that links to admin (not /admin)

Post Reply