This article mainly introduces the usage of widgets in yii. The example analyzes the call methods and definition methods of widgets in the view, which has some reference value. For more information, see
This article mainly introduces the usage of widgets in yii. The example analyzes the call methods and definition methods of widgets in the view, which has some reference value. For more information, see
This example describes the usage of widgets in yii. Share it with you for your reference. The specific analysis is as follows:
The WIDGET definition is simple. If you create a widget named "testWidget. php" under/protected/widget/test.
To call a view, you need to write the following code:
The Code is as follows:
<? Php
$ This-> beginWidget ('application. widget. test. testWidget ');
?>
//... The main content of the widget may need to be used...
<? Php
$ This-> endWidget ();
?>
TestWidget. php file definition method:
The Code is as follows:
/**
* Test widget
*/
Class testWidget extends CWidget
{
Public function init ()
{
// This method is executed when $ this-> beginWidget () is executed in the view.
// You can query data here
}
Public function run ()
{
// This method is executed when $ this-> endWidget () is executed in the view.
// The rendering attempt can be performed here. Note that the view mentioned here is the widget view.
// Note that the widget view is placed under the views directory at the same level as the widget. For example, the following view will be placed in
/// Protected/widget/test/views/test. php
$ This-> render ('test', array (
'Str' => 'widget view variable ',
));
}
}
I hope this article will help you design PHP programs based on the Yii framework.