Zend Framework中模块的URI路由出现问题


Having trouble with URI routing for modules in Zend Framework

我刚开始使用Zend Framework,我不太确定我在URI路由方面做错了什么。

我从Zend Studio中的一个初始Zend Framework项目开始,该项目位于我的htdocs文件夹中(我在Windows7上也使用Zend Server)。到目前为止,索引页的运行似乎很顺利(它已经用完了/public/子目录)。

但是,当我尝试添加一个模块时,在本例中,该模块名为Users,控制器名为Index,并按照说明进行配置时,我不确定应该在URI中放入什么,以使其路由到其视图。我已经尝试了我能想到的URI组合的几乎每一种配置(localhost:80/public/userslocalhost:80/public/users/indexlocalhost:80/users等)

我没有收到路由错误,只是收到了一个普通的404页面。

是否需要将公用文件夹设置为根文件夹?或者我还需要做些什么才能让路线正常工作?

~编辑以响应位正在工作的

看起来它确实会自动将其添加到application.config.php中。但这是用户模块的module.config.php

'router' => array(
    'routes' => array(
        'users' => array(
            'type'    => 'Literal',
            'options' => array(
                // Change this to something specific to your module
                'route'    => '/index',
                'defaults' => array(
                    // Change this value to reflect the namespace in which
                    // the controllers for your module are found
                    '__NAMESPACE__' => 'Users'Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                // This route is a sane default when developing a module;
                // as you solidify the routes for your module, however,
                // you may want to remove it and replace it with more
                // specific routes.
                '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(
                        ),
                    ),
                ),
            ),
        ),
    ),
),

现在我确实看到了它在哪里指导你定制路线。我也尝试过这个,但仍然不确定我应该把它们设置为什么。

如果你想用/users调用用户模块中的索引控制器,你必须相应地命名路由:

...
'users' => array(
    'type'    => 'Literal',
    'options' => array(
        // Change this to something specific to your module
        'route'    => '/users',
                      ---------
        ...

否则请控制application.config.php。它应该看起来像:

return array(
    'modules' => array(
        'Application',
        'Users',
    ),
    ...

所以Url应该看起来像:

localhost/public/users -> Users/Controller/IndexController/indexAction
localhost/public/users/foo -> Users/Controller/FooController/indexAction
localhost/public/users/foo/bar -> Users/Controller/FooController/barAction