Thursday, January 26, 2012

Zend Framework: partial() and render()

partial() will render a view script, and render() will render a view script. So… which one do I have to use?

All depends on the variable scope.

Render()

The render() function will render the given view script within the variable scope of the script is was called from.
$this->render('controllername/actionname');

Partial()

partial() will also render the given view script, but you can define a special variable scope: you can pass all requested parameters in an array.
$this->partial('controllername/actionname', array('var1' => 'value 1', 'var2' => 'value 2'));
 
If you want to render a script from another module, for example( if ypu are in a frontend module, and for some reason you want to render a view from background cms module )
$this->partial('controllername/actionname', 'cms_module_name', array('var1' => 'value 1', 'var2' => 'value 2'));

No comments:

Post a Comment