Home  >  Article  >  Backend Development  >  The difference between render and renderPartial in Yii, yiirenderpartial_PHP tutorial

The difference between render and renderPartial in Yii, yiirenderpartial_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:19:29807browse

The difference between render and renderPartial in Yii, yiirenderpartial

The following are some of the experiences we gained when developing projects at Xinyi Network Company
When rendering page output.

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.

At the same time, there is an important difference:

The processOutput($output) function is executed by default within the

render function, which will register components such as CTreeView to
in CClientScript. Required scripts for rendering output.

And renderPartial() does not automatically render and output client scripts by default. You need to specify parameters before outputting:
renderPartial($view,$data=null,$return=false,$processOutput=false)
Just specify processOutput as true.

For example, if you want to partially output CTreeView, use renderPartial for rendering. If you follow the default processOutput=false, the content will be output without client scripts
The output content is a normal ul list. There is no tree-shaped folding effect. After actively setting processOutput=true, all client scripts required by CTreeView will be output normally at the front of the list.

The following introduces several related functions to be used:

render, renderPartial will no longer be introduced
processOutput()

<&#63;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 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 is quite useful in actual operation. For example, if you don’t want to use a large component, you can directly input the variables into the template, or you can input multiple variables into an array into the template.

How should I write if mainphp in yii framework layouts wants to reference another page? render doesn’t seem to work

Just require. If you have to use render(), use renderPartial()

yii How to jump to the parent page through 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,));

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/874113.htmlTechArticleThe difference between render and renderPartial in Yii, yiirenderpartial The following was finalized when we were developing projects at Xinyi Network Company Some experience when rendering page output. 1...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn