Usage of widgets in yii, usage of yiiwidget _ PHP Tutorial

Source: Internet
Author: User
Widget usage in yii and yiiwidget usage. The usage of the widget in yii. the usage of the yiiwidget in this article describes the usage of the widget in yii. Share it with you for your reference. The specific analysis is as follows: WIDGET definition is very simple. if you use widgets in pro yii, yiiwidget usage

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.

Examples in this article describes the usage of widgets in yii. Share it with you for your reference. The specific analysis is as follows: the WIDGET definition is very simple, if you are in/pro...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.