


PHP development framework Yii Framework tutorial (9) UI widget Widget overview
Like the usual application development framework, Yii Framework also provides a set of UI widgets (CWidget) to help programmers design user interfaces. The group is an instance of CWidget or its subclass. It is mainly used for presentation Components of data. Groups are often embedded in a view to produce some complex and independent user interface. For example, a calendar widget can be used to render a complex calendar interface. Widgets make user interfaces more reusable.
We can use a widget according to the following view script:
beginWidget('path.to.WidgetClass'); ?>
...The content body that may be obtained by the widget...
endWidget(); >or
widget ('path.to.WidgetClass'); ? >;
The latter is used for components that do not require any body content.
The widget can customize its performance through configuration. This is set by calling CBaseController::beginWidget or CBaseController::widget This is done by initializing the attribute values. For example, when using the CMaskedTextField widget, we want to specify the mask to be used. We do this by passing an array carrying the initialization values of these properties. The key of the array here 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'=>'99/99/9999'));?>继承 CWidget 并覆盖其init() 和 run() 方法,可以定义一个新的小物件: class MyWidget extends CWidget{public function init(){// 此方法会被 CController::beginWidget() 调用}public function run(){// 此方法会被 CController::endWidget() 调用}}
A widget can have its own view just like a controller. By default, the widget's view files are located under the views subdirectory of the directory containing the widget's class files. These views can be rendered by calling CWidget::render(), which is very similar to the controller. The only difference is that, The widget's view has no layout file support. In addition, $this in the widget view points to the widget instance rather than the controller instance.
In the previous article Yii Framework Development Concise Tutorial (8) Using FormModel, it was said that user submission events are processed through CController. By analogy with Windows desktop applications or ASP.Net, Yii View (HTML Form) Similar to WinForm or Asp.Net Page. The control class Controller is similar to the event processing (Code-Behind) class of Windows desktop applications or Asp.Net. Strictly speaking, it is not very appropriate to compare the View (HTML Form) in Yii to WinFrom in the Windows desktop or Asp.Net Page. In fact, the entire HTML (or body) of the view in Yii is equivalent to WinForm or Page. HTML Form is just a subclass of CWidget, corresponding to the CActiveForm UI component. In addition, Yii has built-in the following CWidget types:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



.NET Framework 4 is required by developers and end users to run the latest versions of applications on Windows. However, while downloading and installing .NET Framework 4, many users complained that the installer stopped midway, displaying the following error message - " .NET Framework 4 has not been installed because Download failed with error code 0x800c0006 ". If you are also experiencing it while installing .NETFramework4 on your device then you are at the right place

Whenever your Windows 11 or Windows 10 PC has an upgrade or update issue, you will usually see an error code indicating the actual reason behind the failure. However, sometimes confusion can arise when an upgrade or update fails without an error code being displayed. With handy error codes, you know exactly where the problem is so you can try to fix it. But since no error code appears, it becomes challenging to identify the issue and resolve it. This will take up a lot of your time to simply find out the reason behind the error. In this case, you can try using a dedicated tool called SetupDiag provided by Microsoft that helps you easily identify the real reason behind the error.
![SCNotification has stopped working [5 steps to fix it]](https://img.php.cn/upload/article/000/887/227/168433050522031.png?x-oss-process=image/resize,m_fill,h_207,w_330)
As a Windows user, you are likely to encounter SCNotification has stopped working error every time you start your computer. SCNotification.exe is a Microsoft system notification file that crashes every time you start your PC due to permission errors and network failures. This error is also known by its problematic event name. So you might not see this as SCNotification having stopped working, but as bug clr20r3. In this article, we will explore all the steps you need to take to fix SCNotification has stopped working so that it doesn’t bother you again. What is SCNotification.e

Microsoft Windows users who have installed Microsoft.NET version 4.5.2, 4.6, or 4.6.1 must install a newer version of the Microsoft Framework if they want Microsoft to support the framework through future product updates. According to Microsoft, all three frameworks will cease support on April 26, 2022. After the support date ends, the product will not receive "security fixes or technical support." Most home devices are kept up to date through Windows updates. These devices already have newer versions of frameworks installed, such as .NET Framework 4.8. Devices that are not updating automatically may

It's been a week since we talked about the new safe mode bug affecting users who installed KB5012643 for Windows 11. This pesky issue didn't appear on the list of known issues Microsoft posted on launch day, thus catching everyone by surprise. Well, just when you thought things couldn't get any worse, Microsoft drops another bomb for users who have installed this cumulative update. Windows 11 Build 22000.652 causes more problems So the tech company is warning Windows 11 users that they may experience problems launching and using some .NET Framework 3.5 applications. Sound familiar? But please don't be surprised

With the continuous development of cloud computing technology, data backup has become something that every enterprise must do. In this context, it is particularly important to develop a highly available cloud backup system. The PHP framework Yii is a powerful framework that can help developers quickly build high-performance web applications. The following will introduce how to use the Yii framework to develop a highly available cloud backup system. Designing the database model In the Yii framework, the database model is a very important part. Because the data backup system requires a lot of tables and relationships

As the demand for web applications continues to grow, developers have more and more choices in choosing development frameworks. Symfony and Yii2 are two popular PHP frameworks. They both have powerful functions and performance, but when faced with the need to develop large-scale web applications, which framework is more suitable? Next we will conduct a comparative analysis of Symphony and Yii2 to help you make a better choice. Basic Overview Symphony is an open source web application framework written in PHP and is built on

The Yii framework is an open source PHP Web application framework that provides numerous tools and components to simplify the process of Web application development, of which data query is one of the important components. In the Yii framework, we can use SQL-like syntax to access the database to query and manipulate data efficiently. The query builder of the Yii framework mainly includes the following types: ActiveRecord query, QueryBuilder query, command query and original SQL query
