PHP development framework YiiFramework tutorial (9) Overview of UI widgets

Source: Internet
Author: User
PHP development framework YiiFramework tutorial (9) Overview of UI widgets

Like the Common Application Development Framework, Yii Framework also provides a set of UI widgets to help programmers design user interfaces. a group is an instance of CWidget or its subclass. it is a component mainly used to represent data. A group is usually embedded in a view to generate complex and independent user interfaces. for example, a small calendar object can be used to render a complex calendar interface. small components make the user interface more reusable.

We can use a small object as follows:

BeginWidget ('path. to. widgetclass');?>
... Content subject that may be obtained by small objects...
EndWidget ();> or

Widget ('path. to. widgetclass ');? >;

The latter is used for components that do not require any body content.

A widget can be configured to customize its performance. you can call CBaseController: beginWidget or CBaseController: widget to set its initialization attribute value. for example, when using a CMaskedTextField small object, we want to specify the used mask. we implement this by passing an array containing the initialization values of these attributes. the key of the array is the name of the attribute, and the value of the array is the value corresponding to the attribute of the small object. as shown below:

$ This-> widget ('cmaskedtextfield', array (
'Mask' => '2017/123'
));
?> Inherit CWidget and overwrite its init () and run () methods to define a new small object:

Class MyWidget extends

CWidget
{
Public function init ()
{
// This method will be called by CController: beginWidget ()
}

Public function run ()
{
// This method will be called by CController: endWidget ()
}
} A widget can have its own view like a controller. by default, view files of small objects are located under the views subdirectory that contains the directory of small component files. these views can be rendered by calling CWidget: render (), which is similar to the controller. the only difference is that the view of a widget does not support layout files. In the widget view, $ this points to a small object instance rather than a controller instance.

In the previous article Yii Framework development concise tutorial (8) using FormModel, the CController is used to handle user-submitted events, and Windows desktop applications or ASP. net. in Yii, The View (HTML Form) is similar to WinForm or Asp.. Net Page. The Controller class is similar to a Windows desktop application or an Asp. Net Event Processing (Code-Behind) class. Strictly speaking, compare Yii visual View (HTML Form) to WinFrom or Asp on Windows desktop. net Page is not very appropriate. In fact, Yii regards the entire HTML (or body) of an image as WinForm or Page. HTML Form is also a subclass of CWidget and corresponds to the CActiveForm UI component. In addition, Yii has the following built-in CWidget type:

The CJuiWidget and CInputWidget are further divided:

The subsequent tutorials will introduce the usage of the UI widgets provided by Yii one by one. in addition to these built-in UI widgets, Yii also supports custom UI widgets.

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.