I'm learning Zend and trying to set a custom view but I'm having trouble.
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');
}
}
The path is correct for the iphone.phtml view. I keep getting this error:
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/Libr开发者_StackOverflow社区aries/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
I changed 'setScriptPath'
to 'addScriptPath'
and it no longer gives the error but totally ignores the $this->view->rendder
It's $this->render()
And not $this->view->render()
In addition to yokoloko's answer, your error handling is not configured properly. It's catching your exceptions and trying to display a friendly error, but you don't have the friendly templates set up.
You should really create the views/scripts/error/error.pthml
template, or turn on exceptions for your application again. (for the development
environment).
resources.frontController.throwExceptions = true
(or similar)
精彩评论