The difference between Yii render and renderpartial _php tutorial

Source: Internet
Author: User
Tags yii
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 ()

PHP
PublicfunctionRender($view,$data=NULL,$return=false)
{
if($this -BeforeRender($view))
{
$output=$this -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 ;
}
}

Publicfunctionrenderpartial($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 the requested view ' {view} '. ',
Array(' {controller} '=Get_class($this),' {view} '=$view)));
}

Public function 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 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

This article by the focus on the Chengdu website Construction of the letter Easy network release, more information about Yii please pay attention to the letter easy network subsequent release, the letter Easy Network's official website http://www.ir58.com

http://www.bkjia.com/PHPjc/767672.html www.bkjia.com true http://www.bkjia.com/PHPjc/767672.html techarticle The following are some of the experiences that we end up with when we develop a project in the E- Mail network, when rendering the page output. 1.render output the contents of the parent template, the content will be rendered, embedded ...

  • 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.