簡體   English   中英

Zend Framework 2格式的帶有參數的URL

[英]Zend framework 2 format url with parameters

我需要在module.config文件中編寫什么才能接受以下格式的路由?

/action/parameter/value

我認為這是在ZF1中默認完成的操作謝謝這是我嘗試的路線,但我無法使其正常工作,我需要的路線是class / less / value,其中less是查詢參數

'classes' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/:lang/classes',
                'defaults' => array(
                    '__NAMESPACE__' => 'Classes\Controller',
                    'controller'    => 'Classes',
                    'action'        => 'index',
                    'lang'          => 'en',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'process' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:action]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'lang'       => '[a-z]{2}',
                        ),
                        'defaults' => array(
                        ),
                    ),
                ),
            ),
        ),

為了幫助您更多,我們將需要查看您當前的路由。

基本上,您將需要一個簡單的分段路線以及相應的操作,然后是一個開放的通配符非必需部分:

'type' => 'Zend\Mvc\Router\Http\Segment',
    'options' => array(
        'route' => '/products[/:action]',
        'defaults' => array(
            'controller' => 'Application\Controller\Products',
            'action' => 'index'
        )
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'wildcard' => array(
            'type' => 'Wildcard'
        )
    )
)

如果我理解正確,那么您希望您的路線包含一個參數。 我在下面更新代碼的方式可以在路由中添加更多約束。 因此,它是動作/較少/語言。 考慮下面的更新代碼,假設我了解您要執行的操作。

'classes' => array(
                'type'    => 'Segment',
                'options' => array(
                    'route'    => '/:lang/classes',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Classes\Controller',
                        'controller'    => 'Classes',
                        'action'        => 'index',
                        'lang'          => 'en',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'process' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:action]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'less'       => '[a-zA-Z0-9_-]*',//edit here
                                'lang'       => '[a-z]{2}',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM