我使用位於config/autoload
的全局文件在Zend Framework 2中做了一個導航。我怎麼能在這個全局文件中獲取路由參數?Zend Framework 2:動態導航和麪包屑
我已經試過這樣:
$helper = new Zend\View\Helper\ServerUrl();
$active_url = $helper->getHost();
但這返回整個URL。 對於exemle我有這樣
www.mysite.com/controller/action/id/3
我需要知道ID的URL。
我的全局文件返回導航鍵,看起來像這樣:
return array(
'navigation' => array(
'default' => array(
array(
'label' => 'Home',
'route' => 'admin',
'active' => true,
'resource' => 'Admin\Controller\Index',
'privilege' => 'index',
'pages' => array(
'label' => 'My posts ',
'route' => 'admin/default',
'params' => array(
'controller' => 'posts',
'action' => 'edit'
),
'resource' => 'Admin\Controller\Posts',
'privilege' => 'edit',
),
)
)
)
);
這一切都做工精細,只要路線不包含參數。如果我的網址包含一個ID參數,我的菜單鏈接和麪包屑就與控制器和沒有ID的動作形式相同。
因此,而不是:
www.mysite.com/posts/edit/id/12
我的鏈接看起來像:
www.mysite.com/posts/edit
你爲什麼想這樣做? 'config/autoload'文件夾中的全局文件和本地文件只能用於聲明常量,而不能用於動態內容。如果你這樣做,你會遇到麻煩。如果不添加更多關於您想要實現的功能的詳細信息,則很難提供替代解決方案... – Wilt
配置在路由發生前加載。你無法做到這一點。 –
@Will我編輯了我的帖子。 – Andreea