我有Zend route& amp; $ this-> 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>
我的网址为 http://127.0.0.10/manage-subcat
&安培;当我在bootstrap&amp;中禁用最后一个路由时然后我写在我的视图文件
<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
此代码示例不适用于自定义路由以及传统路由,我正在尝试确定此示例无法正常工作的原因。
答案 0 :(得分:1)
除zerocrates注明的路由声明格式错误外,它可能只是代码中的拼写错误吗?
我注意到您在一个地方使用$cat->CategoryName
(单数$cat
)而在另一个地方使用$cats->catident
(复数$cats
)。
如果传递null
参数值,路由器将从生成的URL中省略该参数。