Usage of widgets in Yii, Yiiwidget usage _php tutorial

Source: Internet
Author: User

Usage of widgets in Yii, Yiiwidget usage


This example describes the use of widgets in Yii. Share to everyone for your reference. The specific analysis is as follows:

The widget definition is simple, if you set up a widget named "testwidget.php" under/protected/widget/test/.

Calls in the view need to be written like this:
Copy the Code code as follows: <?php
$this->beginwidget (' Application.widget.test.testWidget ');
?>
//... Possible widgets need to be used here for the main content ...
<?php
$this->endwidget ();
?>
How the testwidget.php file is defined:
Copy the Code code as follows:/**
* Test Widget
*/
Class Testwidget extends CWidget
{
Public Function init ()
{
This method is executed when $this->beginwidget () is executed in the view
Query data operations can be done here
}

Public Function Run ()
{
This method is executed when the $this->endwidget () is executed in the view
You can do the rendering attempt here, note that the view mentioned here is the widget view
Note that the widget view is placed under the views directory that is similar to the widget, for example, the following view is placed in the
/protected/widget/test/views/test.php
$this->render (' Test ', Array (
' str ' = ' widget view variable ',
));
}
}

It is hoped that this article is helpful to the PHP program design based on YII framework.

http://www.bkjia.com/PHPjc/920973.html www.bkjia.com true http://www.bkjia.com/PHPjc/920973.html techarticle usage of widgets in Yii, Yiiwidget usage This article describes the use of widgets in Yii. Share to everyone for your reference. The specific analysis is as follows: Widget definition is 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.