【问题标题】:Zend Skeleton Application album tutorial 404Zend Skeleton Application相册教程404
【发布时间】:2015-06-07 15:26:25
【问题描述】:

据我所见,我已经按照Zend skeleton application tutorial 进行了操作(实际上我经历了两次,结果相同)但是当我尝试访问zf2-tutorial.localhost/album 时出现以下错误:

A 404 error occurred
Page not found.
The requested URL could not be matched by routing.

No Exception available
© 2005 - 2015 by Zend Technologies Ltd. All rights reserved.

转到zf2-tutorial.localhost 会显示 Zend 欢迎页面,并且 404 包含在 Zend 样式中,所以至少看起来有些东西在工作。

我已经尝试过针对类似问题 herehere 提供的解决方案,但无济于事,任何想法都将不胜感激。谢谢。

编辑:我在 XAMPP 上本地运行教程。

【问题讨论】:

    标签: php zend-framework zend-framework2


    【解决方案1】:

    为了摆脱与配置服务器相关的问题,我可能会建议您安装 WAMP 服务器。然后通过将 zend 文件上传到子目录,您将能够开始使用 zend。

    【讨论】:

    • 我应该注意到我已经在使用 XAMPP,编辑问题,谢谢。
    • 你的 .htaccess 和路由器配置文件是什么样子的?
    • 完全如tutorial 所示......我的机器上是否还有其他可能导致问题的东西?我还确保我的 httpd.conf 中的“AllowOverride FileInfo”如教程中所述。
    • 如果您使用正常路径而不是 zf2-tutorial.localhost 正常访问脚本,您仍然会遇到相同的错误吗?我记得我在使用 WAMP 时也遇到过同样的情况,据我所知,我只是简单地下载了不是骨架应用程序,而是准备好“包含专辑模块的应用程序”。不幸的是,我现在找不到文件。
    • 使用 localhost/zf2-tutorial 会为欢迎页面和 /album 生成标准 XAMPP 404。上面另一个答案中提供的 .htaccess 与不幸的是我已经实现的完全相同。
    【解决方案2】:

    也尝试使用下面提供的 .htaccess

    RewriteEngine On
    # The following rule tells Apache that if the requested filename
    # exists, simply serve it.
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    # The following rewrites all other queries to index.php. The 
    # condition ensures that if you are using Apache aliases to do
    # mass virtual hosting, the base path will be prepended to 
    # allow proper resolution of the index.php file; it will work
    # in non-aliased environments as well, providing a safe, one-size 
    # fits all solution.
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
    

    【讨论】:

      【解决方案3】:

      似乎这个错误与 .htaccess 无关,它的配置问题。请确保您已在 Album\config\module.config.php 文件中定义了所需的 rotes:

      http://framework.zend.com/manual/current/en/user-guide/routing-and-controllers.html#routing-and-controllers

      【讨论】:

      • 是的,我一直在思考控制器似乎没有执行的相同思路,但我可以确认路由如教程中所述
      • 刚刚尝试在我的测试 ZF2 应用程序中重现您的错误 - 如果我没有在 configs/application.comfig.php 中定义使用的模块(在我的情况下为“用户”),我会收到完全相同的错误文件。检查您的应用程序配置文件并确保它包含 'modules' => array('Application', 'Album')
      • 我可以确认 'modules' => array('Application', 'Album') 存在于我的 /config/application.config.php 中,但我仍然遇到同样的错误。还仔细检查了我的目录结构,以确保如教程中所述,并且一切正常。
      【解决方案4】:

      原来在 module.config.php 中我错误地将带有控制器和路由器的阵列拆分为两个阵列。将它们合二为一似乎解决了这个特殊问题。

      代码如下:

       return array(
       'controllers' => array(
           'invokables' => array(
               'Album\Controller\Album' => 'Album\Controller\AlbumController',
              ),
          ),
      
        'router' => array(
               'routes' => array(
                   'album' => array(
                       'type'    => 'segment',
                       'options' => array(
                           'route'    => '/album[/:action][/:id]',
                           'constraints' => array(
                               'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                               'id'     => '[0-9]+',
                           ),
                           'defaults' => array(
                               'controller' => 'Album\Controller\Album',
                               'action'     => 'index',
                           ),
                       ),
                   ),
               ),
           ), 
      );
      

      【讨论】:

        猜你喜欢
        • 2016-05-30
        • 2015-09-22
        • 1970-01-01
        • 1970-01-01
        • 2014-03-19
        • 2016-08-25
        • 2023-04-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多