我試圖讓一些自定義的路由使用下面的代碼(我只稍微從這裏https://stackoverflow.com/a/4158571/1069232修改)在Magento的事情:Magento的自定義路由器負載控制器,但沒有別的
class Company_Modulename_Controller_Router extends Mage_Core_Controller_Varien_Router_Standard {
public function match(Zend_Controller_Request_Http $request){
$path = explode('/', trim($request->getPathInfo(), '/'));
// If path doesn't match your module requirements
if ($path[1] == 'home.html' || (count($path) > 2 && $path[0] != 'portfolios')) {
return false;
}
// Define initial values for controller initialization
$module = $path[0];
$realModule = 'Company_Modulename';
$controller = 'index';
$action = 'index';
$controllerClassName = $this->_validateControllerClassName(
$realModule,
$controller
);
// If controller was not found
if (!$controllerClassName) {
return false;
}
// Instantiate controller class
$controllerInstance = Mage::getControllerInstance(
$controllerClassName,
$request,
$this->getFront()->getResponse()
);
// If action is not found
if (!$controllerInstance->hasAction($action)) {
return false;
}
// Set request data
$request->setModuleName($module);
$request->setControllerName($controller);
$request->setActionName($action);
$request->setControllerModule($realModule);
// Set your custom request parameter
$request->setParam('url_path', $path[1]);
// dispatch action
$request->setDispatched(true);
$controllerInstance->dispatch($action);
// Indicate that our route was dispatched
return true;
}
}
結果是模板已加載但沒有內容的頁面。如果我在我的控制器中註釋$ this-> loadLayout()/ $ this-> renderLayout(),我可以打印到屏幕上。但是當我嘗試加載模板和/或塊時,它會在某處出現問題。
home.html也加載正常(如果路徑爲home.html,則該方法返回false)。
任何援助將不勝感激。
怎麼樣佈局更新? – Zyava 2012-02-02 19:27:22