doushoubu5360 2012-10-21 16:50
浏览 58

如何在ZF2中编写满足GET参数的路由?

How do I write a route in zf2 that allows for routes like /:controller/:action/* in zf1?

So that it can cater for parameters like controller/action/id/1/page/2 and controller/action?id=1&page=2 ?

A route that caters for parameters like controller/action?id=1&page=2 world be useful for ajax requests.

So my current code looks like this in my module.config.php

return array(
'controllers' => array(
    'invokables' => array(
        'Support\Controller\Support' => 'Support\Controller\SupportController',
    ),
),

'router' => array(
    'routes' => array(
        'support' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/support[/:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Support\Controller\Support',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),
'view_manager' => array(
    'template_path_stack' => array(
        'support' => __DIR__ . '/../view',
    ),
),
  • 写回答

2条回答 默认 最新

  • dongtan4046 2012-10-21 18:04
    关注

    A look at the docs for Zend\Mvc\Router and a quick root around in the module.config.php file for the Application module in the Zend Skeleton Application tell me that you need to set up a route segment router that will match the url's you want to create.

    As well as the Zend Framework docs, there is this slide show introduction to routing in Zend Framework which you may find useful. It has code examples of what you want to achieve.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题