0
votes

I am a begging with ZF2. I try to do a router and when I use in View. I have this error : Fatal error: Uncaught exception 'Zend\Mvc\Router\Exception\RuntimeException' with message 'Route with name "documents" not found'

Can you help me?

This is my code :

<?php
return array(
    'controllers' => array(
        'invokables' => array(
            'Documents\Controller\Documents' => 'Documents\Controller\DocumentsController',

        ),
    ),
    'router' => array(
        'routes' => array(
            'documents' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/DocumentsController[/:action]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',

                    ),
                    'defaults' => array(
                                                    '__NAMESPACE__' => 'Documents\Controller',
                        'controller' => 'Documents\Controller\DocumentsController',
                        'action' => 'add',
                    ),
                )
            )

            )
         )
);

Thanks

1
Could you edit your question to include the code you're using in the view that is generating this error?Tim Fountain

1 Answers

0
votes

The 'route' name you have defined is 'documents'

Try changing the below line

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

with

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


Also in the view file, create the url as - Eg:

<?php echo $this->url('documents', array('action' => 'index')); ?>