ZF-469: Zend_View::render is printing the view instead of just returning the rendered view
Description
From the manual:
"Once you have assigned all needed variables, the controller should tell Zend_View to render a particular view script. Do so by calling the render() method. Note that the method will return the rendered view, not print it, so you need to print or echo it yourself at the appropriate time."
But my view is printed when I call Zend_View::render. To avoid this, I had to call ob_start, then render, then ob_get_clean. I'm rendering a view inside another view, if it matters.
Comments
Posted by Matthew Weier O'Phinney (matthew) on 2006-11-05T21:54:24.000+0000
Examining the code, I'm having trouble seeing how this can happen, and my usage of Zend_View has never resulted in what you describe; $view->render() always returns the output without rendering it.
Can you provide the minimum amount of code necessary to reproduce the issue? (even if it requires blocks from several files) This will help me produce a test case so I can better troubleshoot the issue.
Posted by Carolina Feher da Silva (mirrorball) on 2006-11-05T22:27:50.000+0000
OK, here it is. I should have gotten a blank page, but I got the text in indexIndex.php instead.
File 1: index.php
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . './library/'); include 'Zend.php';
Zend::loadClass('Zend_Controller_Front'); Zend::loadClass('Zend_Controller_RewriteRouter'); $router = new Zend_Controller_RewriteRouter(); $controller = Zend_Controller_Front::getInstance(); $controller->setRouter($router);
Zend::loadClass('Zend_View'); $view = new Zend_View(); $view->setScriptPath('./application/views'); Zend::register('view', $view);
$controller->run('./application/controllers');
File 2: IndexController.php
<?php
class IndexController extends Zend_Controller_Action { public function indexAction() { $view = Zend::registry('view'); $view->content = 'indexIndex.php'; echo $view->render('general.php'); } }
File 3: general.php
<?php $content = $this->render($this->content); // It shouldn't display anything, right?
File 4: indexIndex.php
This text shouldn't be displayed.
Posted by Matthew Weier O'Phinney (matthew) on 2006-11-06T10:30:04.000+0000
Resolved in revision 1477 of subversion.