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

Source: Internet
Author: User
Like the Common Application Development Framework, YiiFramework 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. 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 customize its performance through configuration. this is accomplished by calling CBaseController: beginWidget or CBaseController: widget to set its initialization attribute value .. For example, when using a CMaskedTextField small object, we want to specify the mask to be used. We can implement this by passing an array that carries 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' => '2014/1/123');?> Inherit CWidget and overwrite its init () and run () methods. you can define a new small object: class MyWidget extendsCWidget {public function init () {// this method will be used by CController :: beginWidget () call} 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 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.

The above is the overview of the UI Widget in PHP development Framework Yii Framework tutorial (9). For more information, see PHP Chinese Web (www.php1.cn )!

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.