嘿。 我打算爲我的菜單組件創建一個「當前」類,它創建菜單。爲了找出當前的課程,建議使用$this>getContext()->getRouting()->getCurrentRouteName();
。爲此,我必須爲所有將要存在的菜單元素設置路線。這條路線有什麼問題?
可以說我到目前爲止有兩個元素,一個用於frontpage,另一個用於客戶。每當我瀏覽首頁時,重要的是什麼操作和參數,我希望上面的代碼返回「frontpage」。顧客也一樣。
我現在的客戶規則如下: 的routing.yml
customer: param: { module: customer }
我認爲設立網址並不重要,我已經指定的模塊以客戶。無論使用何種操作,菜單元素都應該具有「當前」類。
我如何鏈接:
if ($current == $name){ echo link_to($name, $link, array("class" => "selected")); }else { echo link_to($name, $link); }
鏈接($鏈接),現在去 「客戶/ some_action」 不工作,他們顯示爲只是 「/」。所以我想在$ link周圍使用url_for,這也不起作用,結果相同。
我的路由規則肯定有問題......因爲當我輸入讓手動說/客戶/新的,我可以看到頁面。如果我從模板中寫出$this>getContext()->getRouting()->getCurrentRouteName();
,它表示默認。所以我的規則根本不起作用。我也嘗試了其他規則,但沒有任何人工作。訣竅是使一個規則適用於模塊客戶下的任何東西..
是的,我改變了我的每個規則後清除我的緩存。
非常感謝。
編輯: 我做了路由規則的工作,但不是爲客戶模塊下的所有行動。我必須爲每個行動制定規則。但是,鏈接仍然斷開,它們顯示「/」。
我的新規則:
customer_index: url: /:module param: { module: customer, action: index } customer_new: url: /:module/:action param: { module: customer, action: new }
這些鏈接都沒有工作: echo link_to("Customers", "@customer_index", array("module" => "customer"));
echo link_to("New customer", "@customer_new", array("module" => "customer"));