zend framework2 - ZF2 router configuration -


i'm newbie in zf2, try write application. , faced problem invokables , routing config.

i have 2 modules configs:

<?php return array( 'controllers' => array(     'invokables' => array(         'index' => 'vocabulary\controller\indexcontroller'         ,'add' => 'vocabulary\controller\addcontroller'         ,'admin' => 'vocabulary\controller\admincontroller'     ) ) ,'router' => array(     'routes' => array(         'vocabulary' => array(             'type' => 'segment'             ,'options' => array(                 'route' => '/vocabulary[/:controller][/:action]'                 ,'constraints' => array(                     'controller' => '[a-za-z][a-za-z0-9_-]*'                     ,'action' => '[a-za-z][a-za-z0-9_-]*'                 )                 ,'defaults' => array(                     'controller' => 'index'                     ,'action' => 'index'                 )             )         )     ) ) 

and

<?php return array( 'controllers' => array(     'invokables' => array(         'admin' => 'lang\controller\admincontroller'         ,'translation' => 'lang\controller\translationcontroller'     ) ) ,'router' => array(     'routes' => array(         'lang' => array(             'type' => 'segment'             ,'options' => array(                 'route' => '/lang[/:controller][/:action]'                 ,'constraints' => array(                     'controller' => '[a-za-z][a-za-z0-9_-]*'                     ,'action' => '[a-za-z][a-za-z0-9_-]*'                 )                 ,'defaults' => array(                     'controller' => 'admin'                     ,'action' => 'index'                 )             )         )     ) ) 

but on page /vocabulary/admin see content of page /lang/admin. seems, problem invokable array's keys "admin" equal. how can modify config make application work correctly? want keep "lang/admin" , "vocabulary/admin" paths.

i tried use "vocabulary\controller\admin" instead of "admin" invokable key, didn't help.

update

i solved problem using variant of configuration (i hope helpful somebody):

return array( 'controllers' => array(     'invokables' => array(         'lang\controller\admin' => 'lang\controller\admincontroller'         ,'lang\controller\translation' => 'lang\controller\translationcontroller'     ) ) ,'router' => array(     'routes' => array(         'lang' => array(             'type' => 'literal'             ,'options' => array(                 'route' => '/lang'                 ,'defaults' => array(                     '__namespace__' => 'lang\controller',                     'controller' => 'lang\controller\admin'                     ,'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(                         ),                     ),                 ),             ),         )     ) ) 

in case view helper command $this->url('lang', array('controller' => 'translation')) returns "lang/", use $this->serverurl('/lang/translation'); both of modules work correctly.

to answer last part of question (as agree @chanlderti on first part) :

in case view helper command $this->url('lang', array('controller' => 'translation')) returns "lang/"

this because "lang" route literal defining "lang/". you're trying define child route's url, full route name "lang/default". code should :

$this->url('lang/default', array('controller' => 'translation')) 

you should define default action child route also. although don't remember if router default index if no action specified.


Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -