开发者

Route-problem modular App with Zend and multilanguage support

I'm struggling with the Zend-Router. I want to chain language in my url. Everything works fine but my modular routing.

If i call: http://domain.de/en/index - the indexAction of my IndexController of the default module is executed and translated.

Same goes for: http://domain.de/en/about So the aboutAction of the IndexController is called.

If i call: http://domain.de/en/forum/index it should execute the indexAction of the IndexController of the forum module. But it does not.

My aim is to shorten my urls as good as possible, so there is no "default" or "index" in it.

Can you help me editing my routes.xml so i get the wanted results?

my routes.xml

<config>
    <routes>
        <sc1 type="Zend_Controller_Router_Route">
            <route>:lang/:@module/:@controller/:@action</route>
            <defaults>
                <lang>de</lang>
                <module>default</module>
                <controller>index</contro开发者_高级运维ller>
                <action>index</action>
            </defaults>
        </sc1>
        <sc2 type="Zend_Controller_Router_Route">
            <route>:lang/:@module/:@action</route>
            <defaults>
                <lang>de</lang>
                <module>default</module>
                <controller>index</controller>
                <action>index</action>
            </defaults>
        </sc2>
        <sc3 type="Zend_Controller_Router_Route">
            <route>:lang/:@controller/:@action</route>
            <defaults>
                <lang>de</lang>
                <module>default</module>
                <controller>index</controller>
                <action>index</action>
            </defaults>
        </sc3>
        <sc4 type="Zend_Controller_Router_Route">
            <route>:lang/:@action</route>
            <defaults>
                <lang>de</lang>
                <module>default</module>
                <controller>index</controller>
                <action>index</action>
            </defaults>
        </sc4>
    </routes>
</config>

Do you have an idee?

Thank you in advance, Tobias


I am not too great at Zend Routes, but looking at your code you need a way to distinguish what module it should go to. You have it set for default for all occurrences. It would be nice if it could be dynamic like you have it, but I think you will need to setup routes specifically for forums etc. Given the Zend needs to know where to send it to. If you can figure out how to use the :@module variable to send it to that module, that would work but I do not know / think that is possible.

After reading through the manual I came up with this structure for you. You will have to define each item, such as forums, you want it to redirect to as show below.

<config>
    <routes>
        <language type="Zend_Controller_Router_Route">
            <route>:language</route>
            <reqs language="[a-z]{2}">
        </language>
        <index type="Zend_Controller_Router_Route_Static">
            <route></route>
            <defaults module="default" controller="index" action="index" />
        </index>
        <about type="Zend_Controller_Router_Route_Static">
            <route>about</route>
            <defaults module="default" controller="index" action="about" />
        </about>
        <forums type="Zend_Controller_Router_Route_Static">
            <route>forums</route>
            <defaults module="forums" controller="index" action="index" />
        </forums>
        <lang-forums type="Zend_Controller_Router_Route_Chain">
            <chain>language, forums</chain>
        </lang-forums>
        <lang-about type="Zend_Controller_Router_Route_Chain">
            <chain>language, about</chain>
        </lang-about>
    </routes>
</config>

I am not 100% sure about the about portion, specifically the chaining, but messing with it should give you the correct way.

EDIT

The below is left in tact just as another possible example. I think I have the correct answer above.

Looking at the Zend Routes Manual it is very confusing on how to set it up. I also do not like working in the xml format, I prefer the .ini, but here is a "psuedo mock up" of how it should work (untested, given it would be hard to test):

lang.index.type = "Zend_Controller_Router_Route"
lang.index.route = ":language"
lang.index.defaults.controller = index
lang.index.defaults.action = index

lang.forums.index.type =  "Zend_Controller_Router_Route_Static"
lang.forums.index.route =  "forums"
lang.forums.index.controller =  forums
lang.forums.index.action =  index

lang.forums.register.type =  "Zend_Controller_Router_Route_Static"
lang.forums.register.route =  "forums/register"
lang.forums.register.controller =  forums
lang.forums.register.action =  register

lang.forums.login.type = "Zend_Controller_Router_Route_Static"
lang.forums.login.route = "forums/login"
lang.forums.login.controller = forums
lang.forums.login.action = login

lang.forums.view.type = "Zend_Controller_Router_Route_Static"
lang.forums.view.route = "forums/thread/:slug"
lang.forums.view.controller = forums
lang.forums.view.action = view

lang.other.index.type = "Zend_Controller_Router_Route_Static"
lang.other.index.route = "other"
lang.other.index.controller = other
lang.other.index.action = index

lang.other.view.type = "Zend_Controller_Router_Route_Static"
lang.other.view.route = "other/:slug"
lang.other.view.controller = other
lang.other.view.action = view

Hopefully that gets you pushed with the right line of thinking of what you need to do. If someone else knows how to do it dynamically, I would totally be interested! I will work on the xml method and see if I cannot decipher how to do it properly from the abysmal documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜