Reputation: 1039
I already developed with ZF1, now I'm playing with ZF2. I have already working the Album application when you follow the tutorial, and everything works. Now I'm wondering how to add new controllers to the Album module.
I create a new empty controller Named TestController and its view. In order to test it I changed module.config.php with the new TestController as default, and it works. After I changed again to the default Album Controller like in the tutorial. And well.. the problem comes when in the add view, from the Album I changed this line
<a href="<?php echo $this->url('test', array('action'=>'index'));?>">Test</a>
and I hit www.testing.loc/add in the browser but only renders a half of the script without any error.
Some of my module.config from the Album module looks like:
<?php
return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
'Album\Controller\Test' => 'Album\Controller\TestController',
),
),
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
),
),
);
Probably is a simply mistake with the parameters provided in the view for the url function, but I proved with others and it was the same. I'm starting with ZF2 but I can't figure out how to do use multiple controllers in the same module. Any advice is very welcome.
Upvotes: 1
Views: 2667
Reputation: 16455
There is no route named test
inside your configuration. Syntax is:
$this->url('ROUTENAME', $routeParams);
Basically what you need to do is change the route:
'router' => array(
'routes' => array(
'test' => array(
//copy the other parts
)
)
)
For further information see Zend\Mvc\Router-Documentation
Upvotes: 4