Zend Framework中模块的URI路由遇到问题 [英] Having trouble with URI routing for modules in Zend Framework

查看:90
本文介绍了Zend Framework中模块的URI路由遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是从Zend Framework开始,我不太确定自己在URI路由上做错了什么.

I'm just starting off with Zend Framework, and I'm not quite sure what I'm doing wrong with the URI routing.

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

I'm starting with an initial Zend Framework project in Zend Studio based in my htdocs folder (I'm using Zend Server as well on Windows 7). Everything up to there seems to be working fine getting the index page up (it's running out of the /public/ subdirectory).

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

But when I try to add a module though, in this case called Users with a controller called Index, and following the instructions in getting that configured, I'm not sure what I should be putting in the URI to get it to route to it's view. I've tried just about every configuration of URI combinations that I can think of (localhost:80/public/users, localhost:80/public/users/index, localhost:80/users, etc)

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

I'm not getting a routing error, but just a plain 404 page.

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

Do I need to set the public folder as the root? Or is there something else I need to do to get the routing to work?

〜编辑以响应bitWorking

~edit in response to bitWorking

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

It looks like it does automatically add it to the application.config.php. But here is the module.config.php of the Users module

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

现在,我确实看到了引导您自定义路线的地方.我也对此进行了尝试,但仍不确定应将其设置为什么.不过要近得多.

Now I do see where it's guiding you to customize the routes. I've experimented with this as well, but still am not sure what I should set them to. Much closer though.

推荐答案

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

If you want to call the Index controller in your Users module with /users you have to name the route accordingly:

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

否则,请控制application.config.php.看起来应该像这样:

Else please control the application.config.php. It should look like:

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

这篇关于Zend Framework中模块的URI路由遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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