Yii render和renderPartial的区别
以下由我们在信易网络公司开发项目的时候终结出的一些经验
在进行页面输出渲染的时候。
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()
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;
}
以上在实际操作中还是比较有用的,比如你不想用大组建,可以直接将变量输到模板,也可以将多个变量组成数组输到模版里面去
本文由专注于成都网站建设的信易网络发布,更多关于yii的信息请关注信易网络随后的发布,信易网络的官网http://www.ir58.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The Jincheng is full of spring flowers, the jade whip and gold are lightly dusted, and the popular main city of the Tang Dynasty, Guangdu Town, has been visually upgraded. It will be unveiled on the test server of the new expansion pack on April 9, and will be with everyone when the new expansion pack is launched. Meet in formal wear!! In recent years, more and more knights have stopped in Guangdu Town. The city has become unprecedentedly grand and busy, and Guangdu Town has become a famous and prosperous resort in the Tang Dynasty. The residents also earned a lot of money. After careful consideration, they decided to spend money to renovate Guangdu Town to make Chengdu more worthy of its reputation as "the first main city of the Tang Dynasty". The classic main city has been visually renovated, the regional layout remains the same, the NPC positions remain unchanged, the exquisite decoration has a new look, and the craftsmen's ingenuity can be seen in every detail! The tour guide is here today, come and take a first look at the new scenery of “Datang’s Popular CBD”! The sun shines on the head of Jincheng, and the light scatters on the flower building. The sun shines widely

In the current information age, big data, artificial intelligence, cloud computing and other technologies have become the focus of major enterprises. Among these technologies, graphics card rendering technology, as a high-performance graphics processing technology, has received more and more attention. Graphics card rendering technology is widely used in game development, film and television special effects, engineering modeling and other fields. For developers, choosing a framework that suits their projects is a very important decision. Among current languages, PHP is a very dynamic language. Some excellent PHP frameworks such as Yii2, Ph

With the continuous development of cloud computing technology, data backup has become something that every enterprise must do. In this context, it is particularly important to develop a highly available cloud backup system. The PHP framework Yii is a powerful framework that can help developers quickly build high-performance web applications. The following will introduce how to use the Yii framework to develop a highly available cloud backup system. Designing the database model In the Yii framework, the database model is a very important part. Because the data backup system requires a lot of tables and relationships

As the Internet continues to develop, the demand for web application development is also getting higher and higher. For developers, developing applications requires a stable, efficient, and powerful framework, which can improve development efficiency. Yii is a leading high-performance PHP framework that provides rich features and good performance. Yii3 is the next generation version of the Yii framework, which further optimizes performance and code quality based on Yii2. In this article, we will introduce how to use Yii3 framework to develop PHP applications.

The Yii framework is an open source PHP Web application framework that provides numerous tools and components to simplify the process of Web application development, of which data query is one of the important components. In the Yii framework, we can use SQL-like syntax to access the database to query and manipulate data efficiently. The query builder of the Yii framework mainly includes the following types: ActiveRecord query, QueryBuilder query, command query and original SQL query

According to news on January 19, the official website of the State Administration for Market Regulation announced the "acquisition of equity interests in TD Tech Co., Ltd. by Huawei Technologies Co., Ltd. and Chengdu High-tech Investment Group Co., Ltd.". This attention-grabbing dispute has a major update. progress. In this transaction, Huawei, Chengdu High-tech and other operators plan to jointly acquire 100% of the shares of TD Tech. Before this transaction, Huawei and Nokia Solutions and Networks GmbH & Co.KG (Nokia) indirectly held 100% of the shares of TD Tech and jointly controlled TD Tech. After the transaction, Huawei, Chengdu High-tech Investment Group Co., Ltd., Chengdu High-tech Jicui Technology Co., Ltd., Huagai Venture Capital Management (Beijing) Co., Ltd., etc.

As the demand for web applications continues to grow, developers have more and more choices in choosing development frameworks. Symfony and Yii2 are two popular PHP frameworks. They both have powerful functions and performance, but when faced with the need to develop large-scale web applications, which framework is more suitable? Next we will conduct a comparative analysis of Symphony and Yii2 to help you make a better choice. Basic Overview Symphony is an open source web application framework written in PHP and is built on

Following the release of the DLC "Heartbeat in the Room", "Done!" I'm surrounded by beautiful women! "The prequel DLC (Chengdu Chapter) has also recently exposed a promotional poster. The DLC will include 5 new heroines and is expected to start filming in Chengdu in early April 2024. The specific release time has not yet been determined. Based on the previous shooting time of the first DLC at the end of November 2023 and the release time on February 5, the prequel DLC may be released in June. However, "Heartbeat in the Room" only has 58% positive reviews on Steam, which is far lower than the 94% positive reviews of the main game. I don't know if the prequel DLC can save it.
