2012-03-09 71 views
2

我使用cakephp 2.0 ACL與Auth組件。 我的組表包含三種類型的管理員,經理和用戶Cakephp用戶類型(組名稱)名稱不附加在路由

我啓用了core.php中的工藝路線文件

Configure::write('Routing.prefixes', array('admin','manager','user')); 

default.thtml中文件包含以下行鏈接到產品:

$this -> Html -> link(__('Products'), array('controller' => 'products','action' => index')); 

當我以管理員身份登錄時,上面的鏈接是http://www.example.com/admin/products/index
當我以管理員身份登錄時,上面的鏈接是http://www.example.com/products/index 組名「manage R」產品

我需要下面的輸出,當我登錄作爲經理

http://www.example.com/manager/products/index    

回答

1

嘗試在視圖中這行之前沒有附加:

$this->Html->link(__('Products'), array('controller' => 'products','action' => index','manager'=>true)); 

如,增加'manager'=>true到傳遞給HtmlHelper::link()方法的選項列表,或者您在URL中需要的任何前綴名稱(即管理員,經理...)。

制定其前綴是當前使用的,你可以使用這個片段:

$opts = Router::parse(Router::url('')); 
$prefix = $opts['prefix']; // Contains 'admin' or 'manager', etc. 

然後,您可以通過$prefix=>true作爲一個選項的HTML鏈接的方法。

+0

如果我給manager => TRUE,並且以ADMIN身份登錄,則URL是http://www.example.com/manager/products/index。 – AnNaMaLaI 2012-03-13 07:39:57

+0

是的 - 你傳遞的前綴名稱的值爲真,所以你會設置''admin'=> true'在你的情況。 – 2012-03-13 08:49:57

+0

我對管理員和管理員都使用相同的鏈接..所以,如果我給這個$ this-> Html-> link(__('Products'),array('controller'=>'products','action'= > index','manager'=> true,'admin'=> true));是正確的 ? – AnNaMaLaI 2012-03-13 10:56:32

相關問題