yii中widget的用法,yiiwidget用法
本文实例讲述了yii中widget的用法。分享给大家供大家参考。具体分析如下:
WIDGET定义很简单,如果你在/protected/widget/test/下建立了一个名为“testWidget.php”的widget。
在视图中调用需要这样写:
复制代码 代码如下:
$this->beginWidget('application.widget.test.testWidget');
?>
//...可能小部件需要用到这里主体内容...
$this->endWidget();
?>
testWidget.php文件的定义方式:
复制代码 代码如下:
/**
* test widget
*/
class testWidget extends CWidget
{
public function init()
{
//当视图中执行$this->beginWidget()时候会执行这个方法
//可以在这里进行查询数据操作
}
public function run()
{
//当视图中执行$this->endWidget()的时候会执行这个方法
//可以在这里进行渲染试图的操作,注意这里提到的视图是widget的视图
//注意widget的视图是放在跟widget同级的views目录下面,例如下面的视图会放置在
// /protected/widget/test/views/test.php
$this->render('test', array(
'str'=>'WIDGET视图变量',
));
}
}
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

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

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
