Table of Contents
Yii中render和renderPartial的区别,yiirenderpartial
yii框架layouts里mainphp想再引用一个页面该怎写?render好像不行
yii 通过redirect()或render 怎跳转到父页面
Home php教程 php手册 Yii中render和renderPartial的区别,yiirenderpartial

Yii中render和renderPartial的区别,yiirenderpartial

Jun 13, 2016 am 09:25 AM
render

Yii中render和renderPartial的区别,yiirenderpartial

以下由我们在信易网络公司开发项目的时候终结出的一些经验
在进行页面输出渲染的时候。

1.render 输出父模板的内容,将渲染的内容,嵌入父模板。|
2.renderPartial 则不输出父模板的内容。只对本次渲染的局部内容,进行输出。

同时还有个重要的区别:

render 函数内部默认执行processOutput($output)函数, 会将把组件,比如 CTreeView 里面注册到 CClientScript 里面的
需要的脚本进行渲染输出。

而renderPartial() 默认不自动渲染输出客户端脚本,需要进行参数的指定,才会输出:
renderPartial($view,$data=null,$return=false,$processOutput=false)
指定processOutput 为 true 即可。

比如要局部输出 CTreeView ,用renderPartial 进行渲染,如果按照默认processOutput=false 则输出内容,不含有客户端脚本
输出内容则为 正常的 ul 列表。没有树形的折叠效果。 主动设定 processOutput=true 后,CTreeView 所需的,所有客户端脚本就会被正常输出在列表的前面。

下面介绍下要用到的几个相关的函数:

render,renderPartial 不再介绍
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;
}
Copy after login

以上在实际操作中还是比较有用的,比如你不想用大组建,可以直接将变量输到模板,也可以将多个变量组成数组输到模版里面去.

yii框架layouts里mainphp想再引用一个页面该怎写?render好像不行

require就行了啊,如果非要用render()的话用renderPartial()
 

yii 通过redirect()或render 怎跳转到父页面

例如:
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,));
 

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement menu drop-down box in vue3 through render function How to implement menu drop-down box in vue3 through render function May 10, 2023 pm 04:28 PM

Technical solution: First write a drop-down box component. First, we first write a component to display the content of the drop-down box. The component name starts with: Select.vue Welfare Mall Saas Platform Activity Customized Rendering Component We want to render this component on the web page. The operation should be like this: when the mouse moves to the product service, render the drop-down box component as a component instance in appropriate location on the page. In vue3, rendering a Vonde, the core logic is as follows: import{createVNode,h,render,VNode}from'vue'importcomponentfrom"./component.

Mpeppe (MPEPE) Coin: A New Contender in the Cryptocurrency Market Attracting Investors from Render (RNDR) and Internet Computer (ICP) Mpeppe (MPEPE) Coin: A New Contender in the Cryptocurrency Market Attracting Investors from Render (RNDR) and Internet Computer (ICP) Sep 03, 2024 pm 02:03 PM

The world of cryptocurrencies is always in flux, with new tokens capturing the attention of seasoned investors looking for the next big opportunity.

Does render mean rendering? Does render mean rendering? Feb 02, 2023 pm 02:52 PM

Render means rendering and is a drawing term. Rendering is the last process of CG, and it is also the stage that finally makes the image conform to the 3D scene. Rendering is called Render in English, and some people will call it shading, but generally Shade is called For shading, Render is called rendering.

HMD Slate Tab 5G leakes as mid-range tablet with Snapdragon 7s Gen 2, 10.6-inch display and Lumia design HMD Slate Tab 5G leakes as mid-range tablet with Snapdragon 7s Gen 2, 10.6-inch display and Lumia design Jun 18, 2024 pm 05:46 PM

With the Skyline, HMD Global is set to unveil a mid-range smartphone in the style of the Nokia Lumia 920 on July 10. According to the latest information from the leaker @smashx_60, the Lumia design will soon also be used for a tablet, which will be c

Is Render coin worth holding for the long term? Is Render Coin worth investing in? Is Render coin worth holding for the long term? Is Render Coin worth investing in? Mar 06, 2024 am 08:31 AM

Render Coin: An investment opportunity worthy of long-term holding Render Coin is a cryptocurrency based on the Ethereum blockchain and is designed to pay for rendering services on the decentralized rendering network Render. The goal is to address the high cost and inefficiency of traditional rendering solutions and provide artists and creators with an affordable and convenient rendering option. The advantage of Render coin is decentralization: Render coin is based on the Ethereum blockchain and has decentralized characteristics, avoiding the single point of failure and high costs of centralized rendering service providers. High efficiency: Render coins use distributed rendering technology to allocate rendering tasks to idle GPUs around the world, greatly improving rendering efficiency. Low cost: Render coin reduces the cost of rendering by eliminating the middleman.

DTX Exchange (DTX) – A New Era in Online Trading DTX Exchange (DTX) – A New Era in Online Trading Aug 12, 2024 am 12:24 AM

People who buy big-name crypto coins like Render (RNDR), Mantle (MNT) and Sei (SEI) are now putting money into DTX Exchange (DTX).

Tips and best practices for using the render function to implement component rendering in Vue Tips and best practices for using the render function to implement component rendering in Vue Jun 25, 2023 am 10:02 AM

Vue.js, as a popular JavaScript framework, provides developers with many useful features. One of the most important features is Vue.js’s component system. Vue.js allows us to write components using native syntax, namely HTML, CSS and JavaScript. This syntax is very elegant and concise, but in some cases it may not be flexible enough. In these cases, using render functions can help us have more control over the component's output. Rendering functions are not a new concept;

Render (RENDER) Rallies 38% in 2 Days After Reclaiming Key Resistance Level Render (RENDER) Rallies 38% in 2 Days After Reclaiming Key Resistance Level Nov 13, 2024 am 12:26 AM

RENDER was swiftly trending upward. The altcoin's momentum was sluggish before the key $5.22 level was broken and the market structure flipped bullishly.

See all articles