1

I have a simple config and controller in module Blog:

module.config.php:

return array(
    'controllers'=>array(
        'invokables'=>array(
            'Blog\Controller\Blog'=>'Blog\Controller\BlogController',
        ),
    ),
    'router'=>array(
        'routes'=>array(
            'blog'=>array(
                'type'=>'literal',
                'options'=>array(
                    'route'=>'/blog',
                    'defaults'=>array(
                        'controller'=>'Blog\Controller\Blog',
                        'action'=>'index',
                    ),
                ),
                'may_terminate'=>true,
                'child_routes'=>array(
                    'rss'=>array(
                        'type'=>'literal',
                        'options' => array(
                            'route'=>'/rss',
                            'defaults'=>array(
                                'action'=>'rss',
                            ),
                        ),
                    ),
                )
            )
        )
    ),
);

BlogController.php:

namespace Blog\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class BlogController extends AbstractActionController
{
    public function indexAction(){
        return new ViewModel(array());
    }

    public function rssAction(){
        return new ViewModel(array());
    }
}

Route /blog works correctly,

but /blog/rss - doesn't work

Zend Framework 2 response with error message:

A 404 error occurred
Page not found.
The requested controller was unable to dispatch the request.
Controller:
    Blog\Controller\Blog
No Exception available

What's wrong? Thanks in advance.

2 Answers2

0

You don't have may_terminate set to true in the `blog/rss' route like you do in its parent.

guessimtoolate
  • 8,372
  • 2
  • 18
  • 26
  • Thank you guessimtoolate, I added 'may_terminate'=>true, to 'blog/rss', but I have the same error. Here is example from zf2 routing manual : http://framework.zend.com/manual/2.3/en/modules/zend.mvc.routing.html but it doesn't work for me. Is I need to change some config params for Zend\Mvc\Router or for other component? – Serge Melnic Apr 14 '15 at 15:35
0

The problem is in matchedRouteName.

With child_routes

protected 'matchedRouteName' => string 'blog/rss' (length=8),

without child_routes

protected 'matchedRouteName' => string 'blog' (length=4)

It generate error in my route treatment and redirect to 404 page when I try access /blog/rss.