The difference between render and renderpartial in Yii, yiirenderpartial_php tutorial

Source: Internet
Author: User
Tags yii

The difference between render and renderpartial in Yii, yiirenderpartial


The following are some of the experiences that we end up with when we develop a project at Shun Yi Network.
When rendering the page output.

1.render outputs the contents of the parent template, and embeds the rendered content into the parent template.
2.renderPartial does not output the contents of the parent template. The output is only for the local content of this rendering.

There is also an important difference:

The Processoutput ($output) function is executed by default inside the render function, which registers the components, such as CTreeView, inside the Cclientscript
The desired script for rendering output.

RenderPartial () does not automatically render the output client script by default, it needs to specify the parameters before output:
RenderPartial ($view, $data =null, $return =false, $processOutput =false)
Specifies that Processoutput is true.

For example, to local output CTreeView, with renderpartial for rendering, if the default Processoutput=false output content, does not contain client script
The output content is a normal UL list. No tree-shaped folding effect. After you have actively set Processoutput=true, all client-side scripts will be output in front of the list CTreeView required.

Here are a few of the related functions to use:

Render,renderpartial no longer introduce
Processoutput ()

<?phppublicfunction render ($view, $data =null, $return =false) {if ($this->beforerender ($view)) {$output = $this-&    Gt;renderpartial ($view, $data, true); if ($layoutFile = $this->getlayoutfile ($this->layout))!==false) $output = $this->renderfile ($layoutFile,    Array (' content ' = $output), true);    $this->afterrender ($view, $output);    $output = $this->processoutput ($output);    if ($return) return $output;  else echo $output; }}publicfunction renderpartial ($view, $data =null, $return =false, $processOutput =false) {if ($viewFile = $this    Getviewfile ($view))!==false) {$output = $this->renderfile ($viewFile, $data, true);    if ($processOutput) $output = $this->processoutput ($output);    if ($return) return $output;  else echo $output; } else thrownewcexception (' yii::t ', ' {controller} cannot find the requested view ' {view} '. ', Array (' {' {Controlle R} ' =>get_class ($this), ' {view} ' = $view))); Publicfunction Processoutput ($output) {YiI::app ()->getclientscript ()->render ($output); If using page caching, we should delay dynamic output replacement if ($this->_dynamicoutput!==null&& $this-&    Gt;iscachingstackempty ()) {$output = $this->processdynamicoutput ($output);  $this->_dynamicoutput=null;  if ($this->_pagestates===null) $this->_pagestates= $this->loadpagestates ();  if (!empty ($this->_pagestates)) $this->savepagestates ($this->_pagestates, $output); return $output;}

The above in the actual operation is still more useful, for example, you do not want to use large-form, you can directly transfer variables to the template, you can also make a number of variables into the module into the inside.


Yii framework layouts mainphp want to refer to a page again how to write? Render doesn't seem to work.

Require, if you have to use render (), use RenderPartial ()

Yii how to jump to the parent page by redirect () or render

For example:
1. Yii::app ()->user->returnurl = Yii::app ()->getbaseurl (). " /STEP/SHOW/ID/1 ";
$this->redirect (Yii::app ()->user->returnurl);
2. $this->redirect (Array (' step/show ', ' id ' =>1));
3. $this->render (' index ', array (' post ' = = $questions));
4. $this->renderpartial (' field_show ', Array (' field ' = = $field, ' key ' =>++ $key,));

http://www.bkjia.com/PHPjc/874113.html www.bkjia.com true http://www.bkjia.com/PHPjc/874113.html techarticle the difference between render and renderpartial in Yii, yiirenderpartial the following are some of the experiences we end up with when we develop a project in the e-mail network, when rendering the page output. 1 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.