Home > PHP Framework > YII > body text

The difference between yii1.0 and 2.0

(*-*)浩
Release: 2019-12-30 14:11:45
Original
2282 people have browsed it

The difference between yii1.0 and 2.0

Please note that Yii 2.0 introduces many new features that are not covered in this chapter. It is highly recommended that you read the entire Definitive Guide to learn about all new features. In this way, you may find that some functions that you had to develop yourself before are now included in the core code. (Recommended learning: yii tutorial)

Installation

Yii 2.0 fully embraces Composer, which is the de facto PHP dependency management tool. Installation of the core framework as well as extensions is handled through Composer. If you want to create a new extension, or rewrite your existing Yii 1.1 extension to be compatible with 2.0, you can refer to the Creating Extensions chapter.

PHP requirements

Yii 2.0 requires PHP 5.4 or higher, which is a huge improvement over the PHP 5.2 required by Yii 1.1 . So there are a lot of notable differences at the language level. The following is a summary of the main changes in the PHP layer:

Namespace

Anonymous functions

Array short syntax [...element...] is used to replace array(.. .element...)

The short format echo tag = in the view file will always be recognized and legal since PHP 5.4, regardless of the setting of short_open_tag, and can be used safely.

SPL Classes and Interfaces

Delayed Static Binding

Date and Time

Traits

intl Yii 2.0 uses the PHP extension intl to support internationalization related functions.

Namespace

The most obvious change in Yii 2.0 is the use of namespaces. Almost every core class introduces a namespace, such as yii\web\Request. The class name prefix "C" in version 1.1 is no longer used. The current naming scheme matches the directory structure. For example, yii\web\Request indicates that the corresponding class file is the web/Request.php file in the Yii framework folder.

(With Yii's class autoloader, you can directly use all core classes without explicitly including specific files.)

Component (Component) and Object (BaseObject )

Yii 2.0 splits the CComponent class in 1.1 into two classes: yii\base\Object and yii\base\Component. The yii\base\Object class is a lightweight base class. You can define object properties through getters and setters.

The Component class inherits from yii\base\Object and further supports events and behaviors.

If you do not need to use events or behaviors, you should consider using the yii\base\Object class as the base class. This class is usually used to represent basic data structures.

The above is the detailed content of The difference between yii1.0 and 2.0. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
yii
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!