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 )!