doormen2014
2014-07-16 08:41
浏览 89
已采纳

Zend framework2 +带参数的路由

I want to write custom routing in Zend framework2. I prepared following code:

'objects' => array(
            'type' => 'Literal',
            'options' => array(
                'route' => '/objects',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller' => 'Index',
                    'action' => 'decode',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type' => 'Segment',
                    'options' => array(
                        'route' => '/[:mask]',
                        'constraints' => array(
                            'mask' => '[a-zA-Z][a-zA-Z0-9_-.,]*',
                        ),
                        'defaults' => array(

                        ),
                    ),
                ),
            ),
        ),

I must routing adres like this:

http://restaurations.en/objects/cracow,0.html

http://restaurations.en/objects/cracow,swam,1.html

http:restaurations.en/objects/swam,3.html

The blod text I must get in my controller. Also, How should I prepre corect router?? How can I do it?

图片转代码服务由CSDN问答提供 功能建议

我想在Zend framework2中编写自定义路由。 我准备了以下代码:

 'objects'=> 数组(
'类型'=>'文字',
'选项'=>数组(
'路由'=>'/ objects',
'默认'=>数组(
'  __NAMESPACE__'=>'应用程序\控制器',
'控制器'=>'索引',
'动作'=>'解码',
),
),
'may_terminate'=&gt  ; true,
'child_routes'=>数组(
'默认'=>数组(
'类型'=>'细分',
'选项'=>数组(
'路线'  =>'/ [:mask]',
'constraints'=> array(
'mask'=>'[a-zA-Z] [a-zA-Z0-9 _-。,] *  ',
),
'默认'=>数组(
 
),
),
),
),
),
   
  
 

我必须像这样路由地址:

http://restaurations.en/objects/ cracow,0.html < / strong>

http://restaurations.en/objects/ 克拉科夫,游泳,1.html

http:restaurations.en / objects / swam,3.html \ n

我必须在我的控制器中获得的blod文本。 另外,我应该如何预制corect路由器? 我该怎么办?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzhi7661 2014-07-16 09:21
    已采纳

    You should add the defaults as well something like this:

    'objects' => array(
            'type' => 'Literal',
            'options' => array(
                'route' => '/objects',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller' => 'Index',
                    'action' => 'decode',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type' => 'Segment',
                    'options' => array(
                        'route' => '/[:mask]',
                        'constraints' => array(
                            'mask' => '[a-zA-Z][a-zA-Z0-9_-.,]*',
                        ),
                        'defaults' => array(
                              '__NAMESPACE__' => 'Application\Controller',
                              'controller' => 'Index',
                              'action' => 'decode',
                        ),
                    ),
                ),
            ),
        ),
    

    Then on your controller to get the param you should do:

     $mask = $this->params()->fromRoute('mask');
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题