PHP Development Framework YII Framework Tutorial (9) UI Widget Overview

Source: Internet
Author: User
Tags html form yii

Like the usual application development framework, the YII framework also provides a set of UI CWidget to help programmers design the user interface, and the team is CWidget Or an instance of its subclass. It is a component that is primarily used to represent data. Teams are typically embedded in a single view to produce complex and independent user interfaces. For example, a calendar widget can be used to render a complex calendar interface. Widgets make the user interface more reusable.

We can use a small object in the following view script:

<?php $this->beginwidget (' Path.to.WidgetClass '),?>     
... Content bodies that may be fetched by small objects ...     
<?php $this->endwidget ();  >

Or

<?php $this->widget (' Path.to.WidgetClass ');? >;

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

The panel can be configured to customize its performance. This is done by calling Cbasecontroller::beginwidget or Cbasecontroller::widget to set its initialization property value. For example, when using Cmaskedtextfield small objects, we want to specify the mask to be used. We do this by passing an array that carries the initialization values of these properties. The key of the array here is the name of the property, and the value of the array is the value of the small object property. As shown in the following:

<?php     
$this->widget (' Cmaskedtextfield ', Array (     
    ' mask ' => ' 99/99/9999 ' 
));     
? >

To inherit CWidget and overwrite its init () and run () methods, you can 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, the view file for the widget is located under the Views subdirectory that contains the group-class file directory. These views can be rendered by calling Cwidget::render (), which is similar to the controller. The only difference is that The view of a small component does not have layout file support. In addition, the $this in the widget view points to a small object instance instead of a controller instance.

A concise tutorial on Yii Framework Development (8) using Formmodel to handle user submissions via Ccontroller, and Windows desktop application or asp.net analogy, Yii view (HTML Form) A page similar to WinForm or asp.net. Control class controller event handling (Code-behind) classes similar to Windows desktop applications or asp.net. Strictly speaking, it is not quite appropriate to compare the view (HTML Form) in Yii to the Winfrom or ASP.net page in the Windows desktop, in fact the entire HTML (or body) of the view in Yii is equal to WinForm or page. The HTML Form is also just a subclass of the cwidget, corresponding to the Cactiveform UI component, and Yii has the following CWidget type built in:

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.