【问题标题】:Routing issues and timeout in Zend Framework 2Zend Framework 2 中的路由问题和超时
【发布时间】:2015-03-07 10:33:51
【问题描述】:

我正在尝试实现下面解释的路由,但遇到了很多麻烦(文档就像一门外语)。每个模块的路由是否应该在该模块的配置文件中单独保存?

  • “路由”:模块/控制器/动作
  • “/”:应用程序/索引/索引
  • “/:example”:应用程序/广告系列/索引(带有参数“广告系列”= [示例])
  • “/admin”:管理员/管理员/索引
  • “/admin/login”:管理员/访问/登录
  • "/admin/:controller/:action": Admin/[已定义]/[已定义]

我已经尝试理解并使用骨架应用程序来执行此操作,并且一切正常到脚本超时的“/admin/controller/action”路由(我猜那里有一个递归循环) .我的路线定义是:

'home' => array(
            'type' => 'literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller'    => 'Application\Controller\Index',
                    'action'        => 'index',
                ),
            ),
        ),
        'campaign' => array(
            'type' => 'segment',
            'options' => array(
                'route'    => '[/:campaign]',
                'constraints' => array(
                    'campaign' => '[a-zA-Z][a-zA-Z0-9_-]*',
                ),
                'defaults' => array(
                    'controller'    => 'Application\Controller\Campaign',
                    'action'        => 'index',
                    'campaign'      => ''
                ),
            ),
        ),
        'admin' => array(
            'type' => 'segment',
            'options' => array(
                'route'    => '/admin',
                'defaults' => array(
                    'controller'    => 'Admin\Controller\Admin',
                    '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(
                        ),
                    ),
                ),
            ),
        ),

【问题讨论】:

  • 添加您尝试访问的网址以及其中哪个网址超时。仅基于直觉,我想说超时并非源于路由本身。可能是控制器操作中的一些错误代码或完全不相关的东西,如服务器配置。
  • 问题现已修复。就像你说的,这与路由器无关。我忘记了我在 404.phtml 文件中有print_r($this),所以内存超时了。

标签: php routes zend-framework2


【解决方案1】:

1) 是的,你应该将路由配置分离到模块,ZF2 会自动合并它。所以你需要将homecampaign路由存储在Application/config/module.config.phpadmin路由在Admin/config/module.config.php

2) 我在您的配置中看不到任何全局错误。两件小事:

2.1) admin 父路由可以使用literal 代替segment

2.2) 如果您想使用:controller 作为路由参数,请务必通过配置的invokables 部分为其创建快捷方式。例如:

'controllers' => array(
    'invokables' => array(
        'index' => 'Application\Controller\Index'
        'admin' => 'Admin\Controller\Admin'
    ),
),

现在,例如,url /admin/admin/updateAdmin\Controller\Admin->updateAction() 连接

3) 我认为仅使用路由配置来创建一些递归循环是不可能的。所以检查你在控制器/服务中的代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 2014-05-02
    • 2015-04-23
    • 1970-01-01
    相关资源
    最近更新 更多