我试图让一些自定义的路由使用下面的代码(我只稍微从这里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