【发布时间】:2012-03-25 01:26:45
【问题描述】:
我一直在按照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/modules/default/views/static-content 文件夹中有一个名为 about.phtml 的视图。
我得到一个错误提示:
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
-
嗯,它应该路由到 about.phtml,因为控制器使用
:page参数来查找正确的视图文件。所以应该是about.phtml -
@haltabush 如果 AlexW 得到解决方案,你能把它标记为答案吗?
标签: zend-framework