2011-08-17 18 views
0

下面是我的routes.xml文件,它被載入到我的Zend Framework應用中。有兩條路線,其中一條應與網址/aanbod/tekoop/huis匹配,另一條應匹配/aanbod/200/gerenoveerde-woningZend Route XML配置無法正常工作

問題是,這兩個示例網址都以細節操作結束,而第一個網址應以索引操作結束。

任何人都可以澄清這個路由設置有什麼問題嗎?

<routes> 

    <property_overview type="Zend_Controller_Router_Route"> 
     <route>/aanbod/:category/:type</route> 
     <reqs category="(tekoop|tehuur)" /> 
     <reqs type="[A-Za-z0-9]+" /> 
     <defaults module="frontend" controller="property" action="index" /> 
    </property_overview> 

    <property_detail type="Zend_Controller_Router_Route"> 
     <route>/aanbod/:propertyid/:slug</route> 
     <reqs propertyid="[0-9]+" /> 
     <reqs slug="(^\s)+" /> 
     <defaults module="frontend" controller="property" action="detail" /> 
    </property_detail> 

</routes> 
+0

不要以正斜槓開始您的路線。該框架處理基礎URL前綴 – Phil 2011-08-17 13:27:37

回答

2

試試這個:

<routes> 

    <property_overview type="Zend_Controller_Router_Route"> 
     <route>aanbod/:category/:type</route> 
     <reqs category="(tekoop|tehuur)" type="[A-Za-z0-9]+" /> 
     <defaults module="frontend" controller="property" action="index" /> 
    </property_overview> 

    <property_detail type="Zend_Controller_Router_Route"> 
     <route>aanbod/:propertyid/:slug</route> 
     <reqs propertyid="[0-9]+" slug="[^\s]+" /> 
     <defaults module="frontend" controller="property" action="detail" /> 
    </property_detail> 

</routes> 

我已經改變:

  • 您應該只有一個'reqs'元素 - 添加不同的要求作爲這個屬性。這就是爲什麼的請求數是在每個路由使用
  • 刪除初始的斜槓您的路線不工作,因爲只有一個主要的原因 - 這也是沒有用處的
  • 改變了蛞蝓模式[^\s]+這意味着「任何一個或多個空間以外的角色',我想這就是你的意思。
+0

完美工作,多個請求標記的確是問題!謝謝crystalclear答案! – ChrisR 2011-08-18 12:09:27

1

我不認爲你可以使用reqs參數來幫助識別Zend_Controller_Router_Route的路線。在你的情況下,你的路由是相同的,並且路由棧是LIFO,「細節」優先。

也許試試用Zend_Controller_Router_Route_Regex代替。

我有一個很難找到的配置方法爲正則表達式的路由器,但它的代碼會看起來像

$route = new Zend_Controller_Router_Route_Regex(
    'aanbod/(tekoop|tehuur)/([A-Za-z0-9]+)', 
    array('controller' => 'property', 'action' => 'index', 'module' => 'frontend'), 
    array(1 => 'category', 2 => 'type') 
); 

$route = new Zend_Controller_Router_Route_Regex(
    'aanbod/(\d+)/(\S+)', 
    array('controller' => 'property', 'action' => 'detail', 'module' => 'frontend'), 
    array(1 => 'propertyid', 2 => 'slug') 
);