How to use widgets in yii, how to use yiiwidget_PHP tutorial

WBOY
Release: 2016-07-13 10:12:24
Original
873 people have browsed it

Usage of widget in yii, usage of yiiwidget

The examples in this article describe the usage of widgets in Yii. Share it with everyone for your reference. The specific analysis is as follows:

WIDGET definition is very simple, if you create a widget named "testWidget.php" under /protected/widget/test/.

To call in the view, you need to write:

Copy code The code is as follows:
$this->beginWidget('application.widget.test.testWidget');
?>
//...Maybe the widget needs to use the main content here...
$this->endWidget();
?>

How the testWidget.php file is defined:
Copy code The code is as follows:
/**
* test widget
*/
class testWidget extends CWidget
{ 
Public function init()
{
//This method will be executed when $this->beginWidget() is executed in the view
//You can perform query data operations here
}

Public function run()
{
//This method will be executed when $this->endWidget() is executed in the view
//You can perform rendering operations here. Note that the view mentioned here is the view of the widget
//Note that the widget’s view is placed under the views directory at the same level as the widget. For example, the following view will be placed under
// /protected/widget/test/views/test.php
           $this->render('test', array(
             'str'=>'WIDGET view variable',
));
}
}

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920973.htmlTechArticleUsage of widgets in yii, yiiwidget usage This article describes the usage of widgets in yii with examples. Share it with everyone for your reference. The specific analysis is as follows: The WIDGET definition is very simple. If you are in /pro...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template