Steve Rayner-2 wrote
> Using ZF2 I need to namespace my controllers because i have the same
> controller names in different modules (ie index controller). If i
> don't name space them some get lost in merged config. So my
> controllers are named as;
> 
> 'controllers' => array(
>     'invokables' => array(
>         'Inventory/Index' => 'Inventory\Controller\IndexController',
>         'Inventory/Items' => 'Inventory\Controller\ItemsController',
>         'Inventory/Categories' =>
> 'Inventory\Controller\CategoriesController',
>         'Inventory/Locations' =>
> 'Inventory\Controller\LocationsController'
>     )
> )
> 
> I would like my URLs to look like this;
> 
>     http://mysite/inventory/items/edit/1
> 
> I don't want to create a seperate route for each controller, because
> if i have 50 controllers i don't want to have 50 routes. That would be
> crazy.
> So i tried to set up a route like this;
> 
> 'route' => '\inventory[\:controller[\:action][\:id]]',
> 'default' => array(
>     'controller' => 'Index',
>     'action' > 'Index'
> )
> 
> However this doesn't work because it looks for a controller named
> index. I need a way of adding a namespace.
> I would have thought this is a fairly normal use case. Basically as per
> ZF1.
> 
> Having seperate routes for each controller is a major problem for me.
> To give an example i have added just five controllers so far and i
> already  have over 120 lines of config code. All of it is just
> repeated blocks of code only the controller name is different. That's
> madness there has to be a better way.
> 
> Is there any way of namespacing controllers and still have a
> controller parameter in the url and retain clean urls?
> I've been looking at the '__NAMESPACE__' array key. However it does
> not seem to have any effect. I've looked through the framework code
> and the only place i can find it is in
> Zend\Mvc\ModuleRouteListener.php (Line 22). This is used in the
> function onRoute(McvEvent e$). However placing echo and die statements
> in this functions leads me to beieve it is never invoked. So I must be
> on the wrong track.
> 
> Any advice appreciated.

Did you try to use standard ZendSekeleton app single route for all your
modules that need /inventory uri:
            'inventory' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/inventory',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action[/:id]]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'id'           => '[0-9]+',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),



-----
Cheers,
--
Luke Mierzwa
--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Name-spacing-controllers-tp4657577p4657582.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to