Zend Framework 2-通过URL的多个模块 [英] Zend Framework 2 - Multiple modules by URL

查看:87
本文介绍了Zend Framework 2-通过URL的多个模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Git的ZendFrameworkSkeleton应用程序,并试图利用其模块部分来拥有多个模块,这些模块可以通过URL进行更改,如下所示:

I'm currently using the ZendFrameworkSkeleton application from Git and am trying to utilize the module part of it to have a multitude of modules, changeable by URL like so:

http://localhost/application/index/index/
http://localhost/guestbook/index/index/
http://localhost/forum/index/index/

此外,您将如何在其中使用语言以进行将来的扩展:

Also, how would you use language in there as well for future expansion:

http://localhost/en/application/index/index/
http://localhost/de/application/index/index/
http://localhost/en/forum/index/index/

我本来以为这几乎是ZF2模块的全部要点,但很惊讶它似乎还没有开箱即用.任何人都知道这是怎么实现的,或者知道它的示例/教程的链接吗?

I would have thought this was pretty much the whole point of ZF2 Modules and am surprised it doesn't seem to work out of the box. Anyone got any idea how this is meant to be done or perhaps a link to an example/tutorial of it?

目前看来,路由器位于每个模块内,而不是整个应用程序内,我本以为应该怎么做... 我有点猜测,您有一个应用程序模块负责路由和全局工作,注入依赖项以及不注入什么,然后还有其他模块来处理不同的工作,例如游戏,帐户,访客留言簿,论坛等.

At the moment it appears that the Router is within each Module rather than the entire entire Application, which I would have thought was how it should be done... I'm sort of guessing that you have one Application module that does the routing and the global stuff, injecting dependencies and what not and then other modules for the different stuff like game, account, guestbook, forum etc.

一旦我弄清楚了,就可以对它进行Github示例应用程序,因为我知道其他人对此感到好奇.

Once I've figured it out I can make a Github example application of it as I know other people are curious about it.

编辑@ 24/11/2011:此后,我在贡献者论坛上遇到了EvanDotPro的帖子,内容是关于他们谈论他们不想采用ZF1模块/控制器/动作方式来做的事情,那么多的需求.他实际上写了一个例子,让它运行这样的东西,但是说它不能100%工作.因此,遇到这篇文章的人都希望了解更多信息,并且更加精明,那就是:https://github.com/EvanDotPro/EdpMagicRoute(如果在阅读本文时仍然存在的话!)

Edit @ 24/11/2011: I've since come across a post by EvanDotPro on the contributor forum about them talking about them not wanting to do the ZF1 module/controller/action way of doing things and that there wasn't that much demand for it. He actually wrote an example that had it running something like this but said it didn't work 100%. So anyone who comes across this post looking for more information and are a little more savvy then this is it: https://github.com/EvanDotPro/EdpMagicRoute (if it still exists at point of reading this!)

推荐答案

要更改路由,您需要编辑Application/confid/module.config.php.找到那里并更改为

To change routing you need to edit Application/confid/module.config.php. Find there and change to

'options' => array(
    'route' => '/[:module/[:controller[/:action]]]', 
    'constraints' => array(
        'module' => '[a-zA-Z][a-zA-Z0-9_-]*', 
        'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
        'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
    ), 
    'defaults' => array(
        'module' => 'Application', 
        'controller' => 'index', 
        'action' => 'index'
    )
)

您可以看到我添加了/[:module以及默认和约束

You can see I added /[:module and deafults and constraint

这篇关于Zend Framework 2-通过URL的多个模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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