【问题标题】:Route fail to work after migrate and upgrade for ZF2ZF2 迁移和升级后路由无法正常工作
【发布时间】:2013-10-06 14:04:42
【问题描述】:

我的 app/modules/ 中有三个模块,分别命名为 Application、Album、Shop。我想使用 HOSTANME/application、HOSTNAME/album 和 HOSTNAME/shop 访问这些模块中的每一个。对于应用程序模块,配置为:

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


'controllers' => array(
    'invokables' => array(
        'Application\Controller\Index' => 'Application\Controller\IndexController', 
        .........
    ),
 },...

应用模块下有多个控制器。通过这种方法,我可以访问如下 URL: http://www.myhostname.com/application/controllerName/actionName 其他两个模块的配置类似。

这适用于上月初的 T61 thinkpad。然后我在我新买的 T410 中重新安装了 Php/apache。我也 git pull 最新的 ZF2 版本:

git log

commit 73e0de644789aa5b712c97f55c512c57c2b9ac76
Merge: 7c65991 d722da5
Author: Matthew Weier O'Phinney <matthew@zend.com>
Date:   Fri Oct 4 11:01:06 2013 -0500

Merge branch 'hotfix/version-composer'

Fix for issue introduced with #5191

但是一切都不再起作用了。我检查了error.log:

[Sun Oct 06 10:47:05 2013] [error] [client 127.0.0.1] 文件不存在:/path/to/app../ChipShop/public/application

但是,它适用于默认路由http://www.myhostname.com

我的配置有什么问题或者某些配置规则被更改了吗?谢谢

[更新]

有类似的帖子ZF2 routing configuration,我试过方法:

'user' => array(
     'type' => 'Zend\Mvc\Router\Http\Literal',
     'options' => array(
          'route'    => '/user',
          'defaults' => array(
                'controller' => 'Application\Controller\User',
                'action'     => 'some-action',
            ),
      ),
) ,

但它仍然不适合我..

解决方案
问题不在代码方面。这是在我的confiuration。 1、我忘了启用apache rewrite模块。正如akond帖子中所说的那样。 2、在virtualHost配置中,

 AllowOverride None 

应该改为

允许全部覆盖

【问题讨论】:

    标签: php apache zend-framework2 url-routing


    【解决方案1】:

    https://github.com/zendframework/zf2 明确指出 master 分支包含 2.2.5dev。开发版本可能不稳定,您不应依赖它们。将作曲家与

    一起使用
    "require": {
        "zendframework/zendframework": "~2.2.0"
    }
    

    你会没事的。


    更新

    错误消息说它找不到应用程序目录。当然它不存在,因为它是虚拟的。这意味着问题根本不在 ZF 路线上。检查一下

    • .htaccess文件存在于public目录下,内容正确
    • Appache 已配置为解析此 .htaccess 文件
    • mod_rewrite 模块已开启。
    • 直到您的public 目录的目录确实存在
    • 并且虚拟主机已附加到此目录。

    【讨论】:

    • 我已经修复了..谢谢.. 错误信息显示它是 apache 配置问题.. 与您所指的类似。:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 2017-08-04
    • 2017-06-10
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多