Zend Framework 2 Album Tutorial 404 error发生 请求的 URL 无法通过路由 MAMP OSX 匹配 [英] Zend Framework 2 Album Tutorial 404 error occurred The requested URL could not be matched by routing MAMP OSX

查看:32
本文介绍了Zend Framework 2 Album Tutorial 404 error发生 请求的 URL 无法通过路由 MAMP OSX 匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚在 IRC 频道 ZFTalk 上也发布了这个,

just posted this on IRC channel ZFTalk too,

希望我能在 ZF2、ZF2 专辑教程、使用 MAMP 的 OSX 上获得一些帮助.骨架框架,主页正在运行.

Hope I can get some help on ZF2, ZF2 Album Tutorial, OSX using MAMP. Skeleton framework, homepage is working.

问题:完成部分:8.5 列出专辑后,您用一些代码填写模块/Album/view/album/album/index.phtml,然后他们要求您预览http://zf2-tutorial.localhost/album.

Issue : After completing section : 8.5 Listing albums, you fill up the module/Album/view/album/album/index.phtml with some code, then they ask you to preview the page on http://zf2-tutorial.localhost/album.

我收到 404,请求的 URL 无法通过路由匹配.

I get a 404, The requested URL could not be matched by routing.

我前往 Google 寻求建议.找到了一个带有教程完全工作模型"的 GIT 存储库,所以我得到了它来比较我的代码.如果我将其设置为另一台主机,我会收到相同的 404 路由消息.

I headed to Google for advice. Found a GIT repository with a 'fully working model' of the Tutorial, so i got this to compare my code with. If i set up this as another host I get the same 404 routing message.

仔细研究手册后,它在开始明确指出,如果您的 httpd.conf/AllowOverride 未设置为 FileInfo,您将无法查看除开始/主页之外的任何内容.

After carefully studying the manual, it explicitly states in the start that you will not be able to view anything other than the start/home page if your httpd.conf / AllowOverride is not set to FileInfo.

决定在整个机器上扫描名为 httpd.conf 的文件,以防万一我更改的路径在启动服务器时不被 MAMP 使用.

Decided to scan the whole machine for files called httpd.conf, just for in case the path to the one I changed is not used by MAMP when powering up the server.

所以找到了3个,全部都改了(虽然找到了3个,但我相信正确的路由是/private/etc)我的问题仍然存在于我在教程中写的代码中,以及GIT代码中工作模式".

So found 3, changed all of them (Although 3 we're found, I believe the correct route is /private/etc) My problem still exists in the code i wrote from the tutorial, as well as the GIT code of the 'working model'.

有人遇到过这个问题吗?在 stackoverflow Zend Framework 2 .htaccess mamp pro 上找到了这个,它与我的有相似之处问题,但尚未解决.这里有人可以帮助我吗?

Has anyone encountered issues with this? found this on stackoverflow Zend Framework 2 .htaccess mamp pro which has similarities to my problem but has not resolved it. Can anyone in here help me?

采用的其他路由包括:检查代码中的拼写错误,检查 application.config.php 是否设置了路由.请指教?:)

Other routes taken involve : Checking for spelling mistakes in the code, checking the application.config.php has a route set up. Please advise? :)

模块.php

<?php
namespace Album;

use AlbumModelAlbum;
use AlbumModelAlbumTable;
use ZendDbResultSetResultSet;
use ZendDbTableGatewayTableGateway;

class Module
{
    public function getAutoloaderConfig()
    {
        return array(
            'ZendLoaderClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            ),
            'ZendLoaderStandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getServiceConfig()
    {
        return array(
            'factories' => array(
                'AlbumModelAlbumTable' =>  function($sm) {
                    $tableGateway = $sm->get('AlbumTableGateway');
                    $table = new AlbumTable($tableGateway);
                    return $table;
                },
                'AlbumTableGateway' => function ($sm) {
                    $dbAdapter = $sm->get('ZendDbAdapterAdapter');
                    $resultSetPrototype = new ResultSet();
                    $resultSetPrototype->setArrayObjectPrototype(new Album());
                    return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
                },
            ),
        );
    }
}

module.config.php

module.config.php

<?php
return array(
    'controllers' => array(
        'invokables' => array(
            'AlbumControllerAlbum' => 'AlbumControllerAlbumController',
        ),
    ),
    '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' => 'AlbumControllerAlbum',
                        'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',
        ),
    ),
);

推荐答案

您可以解决的是通过配置(httpd.conf)中的 apache 设置更改AllowOverride None"到AllowOverride All".这样的设置允许您通过 .htaccess

You can solve is by configuring the apache settings in (httpd.conf) change the "AllowOverride None" to "AllowOverride All". Such setting permit you to override the config value by .htaccess

这篇关于Zend Framework 2 Album Tutorial 404 error发生 请求的 URL 无法通过路由 MAMP OSX 匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆