zf2专辑教程:希望不必在uri

时间:2015-04-26 22:02:03

标签: php zend-framework2

我是Zend Framework 2的新手。这个问题属于"专辑" Getting Started: A Skeleton Application

中的教程

我使用git进行安装,使用composer来安装依赖项。

我复制了教程文件夹,设置了数据库等等。

这一切似乎都有效,除了我必须输入完全限定的url才能进入索引页面:

http://zf2-tutorial.localhost/album/index

...然后所有内容都显示为(我的相册,添加,编辑,删除表单工作)

如果我只输入

,我很确定它应该有效

http://zf2-tutorial.localhost/album/

如果我遗漏了最后一段index,我会收到此错误:

  

发生404错误   页面未找到。

     

路由无法匹配请求的网址。

这是我的module.config.php:

return array(
'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Album\Controller\Album',
                    'action'     => 'index',
                ),
            ),
        ),
        // The following is a route to simplify getting started creating
        // new controllers and actions without needing to create a new
        // module. Simply drop new controllers in, and you can access them
        // using the path /application/:controller/:action
        'application' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/application',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\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(
                        ),
                    ),
                ),
            ),
        ),
    ),
),
'service_manager' => array(
    'factories' => array(
        'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
    ),
),
'translator' => array(
    'locale' => 'en_US',
    'translation_patterns' => array(
        array(
            'type'     => 'gettext',
            'base_dir' => __DIR__ . '/../language',
            'pattern'  => '%s.mo',
        ),
    ),
),
'controllers' => array(
    'invokables' => array(
        'Application\Controller\Index' => 'Application\Controller\IndexController'
    ),
),
'view_manager' => array(
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
    'doctype'                  => 'HTML5',
    'not_found_template'       => 'error/404',
    'exception_template'       => 'error/index',
    'template_map' => array(
        'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
        'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
        'error/404'               => __DIR__ . '/../view/error/404.phtml',
        'error/index'             => __DIR__ . '/../view/error/index.phtml',
    ),
    'template_path_stack' => array(
        __DIR__ . '/../view',
    ),
),
)

如果我的虚拟主机很重要,那么它就是:

<VirtualHost 127.0.0.2:80>
 DocumentRoot "C:\xampp\htdocs\zend\public"

 RewriteEngine off

 ServerName zf2-tutorial.localhost
 ErrorLog "C:\xampp\htdocs\zend\error.log"
 SetEnv APPLICATION_ENV "ZF2_PATH"
 SetEnv ZF2_PATH
 <Directory "C:\xampp\htdocs\zend" >
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
 </Directory>
</VirtualHost>

1 个答案:

答案 0 :(得分:1)

您需要为操作设置“默认”参数值。

error_reporting(1);