The following are some of the experiences we have gained when developing projects in Xinyi network.
During page output rendering.
1. render outputs the content of the parent template and embeds the rendered content into the parent template. |
2. renderPartial does not output the content of the parent template. Only the partial content of this rendering is output.
There is also an important difference:
The render function executes the processOutput ($ output) function by default, and registers components, such as
The required script for rendering and output.
RenderPartial () does not automatically render the output client script by default. You need to specify the parameters before the output:
RenderPartial ($ view, $ data = null, $ return = false, $ processOutput = false)
Set processOutput to true.
For example, to locally output the CTreeView, use renderPartial for rendering. If the default value is processOutput = false, the output content does not contain client scripts.
The output content is a normal ul list. There is no tree-like folding effect. After processOutput is set to true, all client scripts required by CTreeView will be normally output in front of the list.
The following describes the functions to be used:
Render, renderPartial not introduced
ProcessOutput ()
<? Php
Publicfunction render ($ 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;
}
}
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 the requested view "{view }".',
Array ('{controller}' => get_class ($ this), '{view}' => $ view )));
}
Publicfunction processOutput ($ output)
{
Yii: app ()-> getClientScript ()-> render ($ output );
// If using page caching, we shocould 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 is useful in actual operations. For example, if you do not want to use a large component, you can directly input the variables to the template, or you can input multiple variables into an array.
This article is published by Xinyi network, which focuses on website construction in Chengdu,