繁体   English   中英

Zend Framework中模块的URI路由遇到问题

[英]Having trouble with URI routing for modules in Zend Framework

我只是从Zend Framework开始,我不确定URI路由做错了什么。

我将从htdocs文件夹中的Zend Studio中的初始Zend Framework项目开始(我在Windows 7上也使用Zend Server)。 到目前为止,一切似乎都可以正常工作,以建立索引页(它已耗尽/ public /子目录)。

但是,当我尝试添加一个模块(在这种情况下,称为“用户”,带有一个名为“索引”的控制器)并按照说明进行配置时,我不确定应该在URI中放入什么以使其路由到视图。 我已经尝试了几乎所有可以想到的URI组合配置( localhost:80/public/userslocalhost:80/public/users/indexlocalhost:80/users等)

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

我是否需要将公用文件夹设置为根目录? 还是我需要做一些其他事情才能使路由正常工作?

〜编辑以响应bitWorking

看起来它确实会自动将其添加到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模块中调用Index控制器,则必须相应地命名路由:

...
'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',
    ),
    ...

因此,网址应如下所示:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM