2010-09-22 78 views
1

我在Zend-Router上苦苦掙扎。我想在我的網址中鏈接語言。一切正常,但我的模塊化路由。支持Zend和多語言支持的路由問題模塊化應用

如果我打電話:http://domain.de/en/index - 我的IndexController的默認模塊的indexAction被執行和翻譯。

同樣如下: http://domain.de/en/about所以調用IndexController的aboutAction。

如果我打電話給:http://domain.de/en/forum/index它應該執行論壇模塊的IndexController的indexAction。但事實並非如此。

我的目標是儘可能縮短我的網址,因此它沒有「默認」或「索引」。

你能幫我編輯我的routes.xml,所以我得到想要的結果嗎?

我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</controller> 
       <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> 

你有一個愛迪?

謝謝你在前進, 托比亞斯

回答

1

我沒有太大的Zend的路線,而是看你的代碼,你需要一種方法來區分它應該去哪些模塊。您已將其設置爲所有事件的默認設置。如果它可以像你一樣具有動態性,那將是非常好的,但我認爲你需要爲論壇等設置路由。鑑於Zend需要知道將它發送到哪裏。如果你可以弄清楚如何使用:@module變量將它發送到那個模塊,那可行,但我不知道/認爲這是可能的。

閱讀完手冊後,我想出了這個結構。您將必須定義您希望它重定向到的每個項目,例如論壇,如下所示。

<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> 

我不是100%地肯定了about部分,特別是鏈接,但它搞亂應該給你正確的方法。

EDIT

的下面在生產節拍左正如另一種可能的例子。我想我上面有正確的答案。

看着Zend Routes Manual它是如何設置它很混亂。我也不喜歡在XML格式的工作,我更喜歡在.ini,但這裏是一個「僞小樣」它應該如何工作(未經測試,因爲這將是很難進行測試):

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 

希望能讓你以正確的思路來推動你需要做的事情。如果有人知道如何動態地做,我完全有興趣!我將研究xml方法,看看我是否無法解釋如何從糟糕的文檔中正確地做到這一點。

+0

但是,還有沒有更好的辦法比手動聲明一切? 我的意思是模塊化路線工作得很好。只有當我想要鏈接語言時,我的模塊纔不再可用。 – 2010-09-22 19:32:33

+0

不是我所知道的。如果你能測試/發現它,我會有興趣知道。我能看到的唯一方法是在聲明中使用變量IE:' @:module'但我非常懷疑這是可能的。 – 2010-09-22 19:34:51