我的情況與Zend路線& $這個 - > URL方法
在我的bootstrap.php我有幾條路線爲
$route = new Zend_Controller_Router_Route(
'dashboard',
array(
'action' => 'index',
'controller' => 'index',
'module' => 'dashboard',
'isAdmin' => true
)
);
$router->addRoute('dashboard', $route);
$route = new Zend_Controller_Router_Route(
'logout',
array(
'action' => 'logout',
'controller' => 'index',
'module' => 'main',
'isAdmin' => true
)
);
$router->addRoute('logout', $route);
$route = new Zend_Controller_Router_Route(
'manage-users',
array(
'action' => 'list',
'controller' => 'index',
'module' => 'main',
'isAdmin' => true
)
);
$router->addRoute('manage-users', $route);
$route = new Zend_Controller_Router_Route(
'edit-user/:id',
array(
'action' => 'edit',
'controller' => 'index',
'module' => 'main',
),
array('id' => '[0-9]+')
);
$router->addRoute('edit-user', $route);
$route = new Zend_Controller_Router_Route(
'/manage-subcat/:ident',
array(
'action' => 'index',
'controller' => 'subcategory',
'module' => 'category',
'ident' => '',
array(
'ident' => '[a-zA-Z-_0-9]+',
)
)
);
$router->addRoute('manage-subcat', $route);
需要的情況下,最後路線
在我看來,當我寫
<a href="<?php echo $this->url(array ('controller'=> 'subcategory', 'action'=> 'index', 'module'=> 'category', 'ident' => $cats->catident), 'manage-subcat', true) ?>"><?php echo $cat->CategoryName ?></a>
我得到URL爲http://127.0.0.10/manage-subcat
&當我禁用引導&那麼最後的路線我在查看文件
<a href="<?php echo $this->url(array ('controller'=> 'subcategory', 'action'=> 'index', 'module'=> 'category', 'ident' => $cats->catident)) ?>"><?php echo $cat->CategoryName ?></a>
寫我得到URL作爲同一HTTP:/ /127.0.0.10/category/subcategory
理想情況下,我應該得到http://127.0.0.10/category/subcategory/ident/some-category這一個
&爲前一個應該http://127.0.0.10/manage-subcat/ident/some-category
此代碼示例不與自定義的路線以及傳統路線,而我的工作我試圖確定爲什麼這個示例不能正常工作。
最後一個路由的「驗證」數組在「defaults」數組內。 – 2011-04-08 17:57:07
@zerocratesü的意思是說我應該將其更改爲這個>> '$路線=新Zend_Controller_Router_Route中( '/管理-SUBCAT /:IDENT', 陣列( '動作'=> '指數', 「控制器'=>'子類別', 'module'=>'category', 'ident'=>'', ), array( 'ident'=>'[a-zA-Z-_0-9 ] +', ) ); $ router-> addRoute('manage-subcat',$ route);' 確定這是一個愚蠢的錯誤,我也這樣做了但URL沒有:ident屬性 – ankur 2011-04-08 19:27:35
@zerocrates謝謝你的幫助 – ankur 2011-04-08 19:31:21