When using setScriptPath() or addScriptPath you need to specify an absolute directory path or the path to your current directory. For portability, it is better to use the absolute path.
When calling Zend_View::render() you must pass the name of the script, including its extension.
Based on your last example, try something like this:
$view->setScriptPath(APPLICATION_PATH . '/views/'); $html = $view->render('news.phtml');
Just make sure the right way. My example assumes you have views in your application folder.
EDIT: If you are in a controller and want to use a different view of the script , use the Renderer View Helper :
$this->_helper->viewRenderer->setRender('news');
This tells the news.phtml to look for the view script news.phtml instead of the name of your action. However, it still looks in views/scripts/controller/ for news.phtml. Therefore, you will need the following changes:
// set view script path to the base of the views folder $this->view->setScriptPath(APPLICATION_PATH . '/views/'); $this->_helper ->viewRenderer ->setNeverController(true) // do not render into controller subdirectories ->setRender('news'); // set render script to news.phtml
When you use the Zend Application, it does its own rendering of the view, so if you are not trying to display html for use directly, you should not use Zend_View yourself. After your controller action method completes, the Zend application will automatically display the script view and try to display it along with any layout in the browser. If you created your own Zend_View, you will need to complete the request before the action completes, and not to display any other content. There are also ways to turn off the display of a layout or view as an alternative.
source share