我一直對如何從書上創建自定義路線的指令之後Zend Framework - A Beginners Guide無效使用控制器定製路由
我已經改變了我application.ini
文件,包括該路由信息:
resources.router.routes.static-content.route = /content/:page
resources.router.routes.static-content.defaults.module = default
resources.router.routes.static-content.defaults.controller = static-content
resources.router.routes.static-content.defaults.view = static-content
resources.router.routes.static-content.defaults.action = display
鑑於上述結構中,我有這樣的控制器:
<?php
class Default_StaticContentController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function displayAction()
{
// action body
$page = $this->getRequest()->getParam('page');
if (file_exists($this->view->getScriptPath(null) .
'/' . $this->getRequest()->getControllerName() . '/' .
$page . $this->viewSuffix
)) {
$this->render($page);
}
else {
throw new Zend_Controller_Action_Exception('HLC - Page not found', 404);
}
}
}
我有一個在APPLICATION_PATH /模塊/默認/視圖名爲about.phtml
視圖/靜態內容文件夾。
什麼ahppens是我得到一個錯誤說:
An error occurred
Page not found
Exception information:
Message: Invalid controller class ("StaticContentController")
Stack trace:
#0 /Applications/MAMP/htdocs/zend/library/Zend/Controller/Dispatcher/Standard.php(262): Zend_Controller_Dispatcher_Standard->loadClass('StaticContentCo...')
#1 /Applications/MAMP/htdocs/zend/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#2 /Applications/MAMP/htdocs/zend/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#3 /Applications/MAMP/htdocs/zend/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#4 /Applications/MAMP/htdocs/HLC/public/index.php(26): Zend_Application->run()
#5 {main}
Request Parameters:
array (
'page' => 'about',
'module' => 'default',
'controller' => 'static-content',
'view' => 'static-content',
'action' => 'display',
)
注意,它不是我的渲染定製Zend_Controller_Action_Exception
但扔全局錯誤。
我使用的網址:http://hlc.local:8888/content/about
默認索引操作工作正常,只是該路由無法運作。
我認爲你有問題,你的看法,應該是display.phtml – haltabush 2012-03-25 01:32:54
那麼,它應該路由到about.phtml作爲控制器使用':page'參數找到正確的視圖文件。所以它應該是關於.phtml – Alex 2012-03-25 01:35:05
OUPS,我的壞,對不起 – haltabush 2012-03-25 01:36:18