我在爲我的博客模塊創建自定義路由時遇到了一些麻煩(我正在更好地學習Magento)。自定義slu M Magento
我到目前爲止所做的: 創建了一個也包含所需slu custom的自定義表。 加在我的config.xml中的下列
<default>
<web> <!-- what does this represent??? -->
<routers>
<namespace_blog_list>
<area>frontend</area>
<class>Namespace_Blog_Controller_Router</class>
</namespace_blog_list>
</routers>
</web>
</default>
所以,我創建了Namespace_Blog_Controller_Router
類,並從CMS控制器複製match()
方法,但不太清楚如何對其進行修改。
這是我到目前爲止有:
// $identifier is 'blog/view/my-slug-name';
$parts = explode('/', $identifier);
if ($parts[0] == 'blog') {
$post = Mage::getModel('namespace_blog/post');
$routeInformation = $post->checkIdentifier($identifier);
$request->setModuleName('namespace_blog')
->setControllerName($routeInformation['controller'])
->setActionName($routeInformation['action']);
if (isset($routeInformation['params']) && count($routeInformation['params'])) {
foreach ($routeInformation['params'] as $key => $param) {
$request->setParam($key, $param);
}
}
$request->setAlias(
Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
$identifier
);
return true;
}
PS:$後> checkIdentifier返回以下陣列:
array(
'controller' => 'index',
'action' => 'index',
'params' => array(
'id' => 3
)
)
的問題是,它會在一個無限循環,我發現以下報告:
a:5:{i:0;s:52:"Front controller reached 100 router match iterations";i:1;s:337:"#0 /var/www/app/code/core/Mage/Core/Controller/Varien/Front.php(183): Mage::throwException('Front controlle...')
#1 /var/www/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#2 /var/www/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#3 /var/www/index.php(87): Mage::run('', 'store')
#4 {main}";s:3:"url";s:21:"/index.php/blog/index";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}`
任何想法?這是做這件事的最好方式,還是有另一種推薦的解決方案?
謝謝,
您可以參考Alan Storm的文章詳細瞭解如何在magento工程中路由http://alanstorm.com/category/magento#dispatch –
非常感謝您抽出時間來幫助我,我實際上更瞭解了路由系統如何在magento中工作。我已經檢查了大部分Alan Storms教程,但這是我完全不理解的少數幾個內容之一 –