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.
http://www.bkjia.com/PHPjc/920973.htmlwww.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...