2011-02-03 60 views
0

似乎創造了當前類是比我想象的更難:)我的動態菜單創建一個當前類

模塊/菜單/動作/ components.class.php

 
$this->elements = array(
     "My page" => "content/index", 
     "Admin" => "content/index", 
    ); 

$this->current = ""; 
foreach($this->elements as $name => $link) { 
    list($module, $action) = explode("/", $link); 
    if ($this->getContext()->getModuleName() == $module && 
    $this->getContext()->getActionName() == $action) { 
     $this->current = $name; 
    } 
}    

模塊/菜單/模板/ _main.php

 

if ($current == $name){ 
    echo link_to($name, $link, array("class" => "selected")); 
}else { 
    echo link_to($name, $link); 
} 

如果你看的聯繫,他們到「內容/索引」(現在)。 最大的問題是,內容/索引重定向到auth/login,所以當前模塊和操作,即使URL顯示的內容/索引是auth/login。

感謝

回答

2

只是一個想法:

  1. 設置return參數時重定向頁面
  2. 解析這個參數簽署實際的URL,而不是

或者:

  1. 工作與路線,而不是「模塊操作」對
  2. 前進,而不是重定向到權威性航線
  3. $currentRouteName = $this->getContext()->getRouting()->getCurrentRouteName()

希望這有助於。