使用Zend自定义视图

时间:2011-09-01 16:39:58

标签: zend-framework

我正在学习Zend并尝试设置自定义视图,但我遇到了麻烦。

class AccountController extends Zend_Controller_Action
{
  public function init() {}

  public function indexAction()
  {
    $this->view->setScriptPath(APPLICATION_PATH . '/views/scripts/mobile/');
    $this->view->render('iphone.phtml');
  }
}

iphone.phtml视图的路径正确。我一直收到这个错误:

Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'error/error.phtml' not found in path (/Users/frankie/Websites/learn/zend/project1/application/views/scripts/mobile/)' in /Users/frankie/Websites/Libraries/ZendFramework-1.11.10/library/Zend/View/Abstract.php:988 Stack trace: #0 /Users/frankie/Websites/Libraries/ZendFramework-1.11.10/library/Zend/View/Abstract.php(884): Zend_View_Abstract->_script('error/error.pht...') #1 /Users/frankie/Websites/Libraries/ZendFramework-1.11.10/library/Zend/Controller/Action/Helper/ViewRenderer.php(900): Zend_View_Abstract->render('error/error.pht...') #2 /Users/frankie/Websites/Libraries/ZendFramework-1.11.10/library/Zend/Controller/Action/Helper/ViewRenderer.php(921): Zend_Controller_Action_Helper_ViewRenderer->renderScript('error/error.pht...', NULL) #3 /Users/frankie/Websites/Libraries/ZendFramework-1.11.10/library/Zend/Controller/Action/Helper/ViewRenderer.php(960): Zend_Controller_Action_Helper_ViewRenderer->render() #4 /Users/frankie/Websites/Libraries/ZendFr in /Users/frankie/Websites/Libraries/ZendFramework-1.11.10/library/Zend/Controller/Plugin/Broker.php on line 336

我将'setScriptPath'更改为'addScriptPath',它不再提供错误,但完全忽略了$this->view->rendder

2 个答案:

答案 0 :(得分:3)

它是$this->render()而不是$this->view->render()

答案 1 :(得分:0)

除了yokoloko的回答,您的错误处理配置不正确。它会捕获您的异常并尝试显示友好错误,但您没有设置友好模板。

您应该真正创建views/scripts/error/error.pthml模板,或者再次启用应用程序的例外。 (对于development环境)。

resources.frontController.throwExceptions = true

(或类似)