The difference _php skill of render and renderpartial in Yii

Source: Internet
Author: User
Tags yii

Here are some of the lessons we've ended when we developed a project in the Trust Network company.
At the time of rendering the page output.

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

And there's one important difference:

The render function internally defaults to the Processoutput ($output) function, which registers the component, such as CTreeView, inside the Cclientscript
The required script to render the output.

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

For example, to local output CTreeView, rendering with renderpartial, if you follow the default Processoutput=false output content, does not contain client script
The output is a normal list of UL. There is no tree-shaped folding effect. Once the processoutput=true is active, all client script will be output normally in front of the list, CTreeView required.

Here are a few of the related functions to use:

Render,renderpartial no longer introduce
Processoutput ()

<?php publicfunction Render ($view, $data =null, $return =false) {if ($this->beforerender ($view)) {$output = $thi
    S->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 (' Yii ', ' {controller} cannot find ' requested view ' {view} '. ', Array (' {contro
Ller} ' =>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-
    >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 more useful, for example, you do not want to use a large build, you can directly to the template, you can also make a number of variables to form an array to die version inside.

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.