简体   繁体   中英

ZF2 run the application without using the router

I am learning ZF2.

Is it possible to run the application without Router as in Zf1? Do we need to define router for each controller?

Example:

In ZF1: "admin/index/index" shows as "module/controller/action"

IN ZF2: "admin/index/index" shows as "router[/:controller][/:action]"

please help me to clear my doubts.

Please tyr this

return array(
    // routes
    'router' => array(
        'routes' => array(
            'album' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/album',
                    'defaults' => array(
                        'controller'    => 'album\Controller\Index',
                        '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(
                                 // add the default namespace for :controllers in this route
                                 '__NAMESPACE__' => 'album\Controller',
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),    
    'controllers' => array(
        'invokables' => array(
            'album\Controller\Test' => 'Album\Controller\TestController',
        ),
    ),

    'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',
        ),
    ),
);

You need to add your controller name in invokables manually or invoke via Abstract Factories

'controllers' => array(
   'invokables' => array(
      'album\Controller\Test' => 'Album\Controller\TestController',
   ),
),

Automatic Controller Invokables via Abstract Factories

Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM