Zend Framework 2 - Multiple modules by URL

前端 未结 3 747
谎友^
谎友^ 2020-12-30 18:09

I\'m currently using the ZendFrameworkSkeleton application from Git and am trying to utilize the module part of it to have a multitude of modules, changeable by URL like so:

相关标签:
3条回答
  • 2020-12-30 18:15

    To change routing you need to edit Application/confid/module.config.php. Find there and change to

    'options' => array(
        'route' => '/[:module/[:controller[/:action]]]', 
        'constraints' => array(
            'module' => '[a-zA-Z][a-zA-Z0-9_-]*', 
            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
            'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
        ), 
        'defaults' => array(
            'module' => 'Application', 
            'controller' => 'index', 
            'action' => 'index'
        )
    )
    

    You can see I added /[:module and deafults and constraint

    0 讨论(0)
  • 2020-12-30 18:32

    You can use 'child_routes' attribute in module.config.php file comes under module\Application\config

    'routes' => array(
            'application' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/application',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        '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(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    

    then you can run localhost/application/index/index

    0 讨论(0)
  • 2020-12-30 18:38

    I found nice example on github https://github.com/akrabat/zf2-tutorial + pdf with explanation http://akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework-2.pdf

    0 讨论(0)
提交回复
热议问题