Home > PHP Framework > YII > What is the difference between yii1.1 and yii2.0

What is the difference between yii1.1 and yii2.0

(*-*)浩
Release: 2020-10-21 11:01:18
Original
3042 people have browsed it

Differences: 1. Yii2.0 fully embraces Composer, while yii1.1 does not; 2. Almost every core class in Yii2.0 introduces namespaces, and the class name prefix "C" in version 1.1 is no longer Use; 3. Yii2.0 splits the CComponent class in 1.1 into two classes.

What is the difference between yii1.1 and yii2.0

The 2.0 version of the framework is a complete rewrite, and there are quite a few differences between the 1.1 and 2.0 versions. So upgrading from version 1.1 is not as simple as jumping between minor versions. With this guide you will understand the main differences between the two versions.

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.

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. Here is a summary of the major changes to the PHP layer:

  • Namespace

  • Anonymous Function

  • Array The short syntax [...element...] is used to replace the short form echo tag

  • SPL Classes and Interfaces

  • Delayed Static Binding

  • Date and Time

  • Traits

  • intl Yii 2.0 uses 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 "C" class name prefix in version 1.1 is no longer used.
(Recommended learning:

yii tutorial

) 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 and Object

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

[[yii\base\Component|Component]] class inherits from [[yii\base\Object|Object]], and further supports events and behaviors.

Event (Event)

In Yii 1, events are usually created by defining methods starting with on (such as onBeforeSave). In Yii 2, you can use any event name. At the same time, trigger related events by calling the [[yii\base\Component::trigger()|trigger()]] method:

$event = new \yii\base\Event;
$component->trigger($eventName, $event);
Copy after login

To attach an event handler to an event, you need to use [ [yii\base\Component::on()|on()]] Method:

$component->on($eventName, $handler);
// 解除事件处理器,使用 off 方法:
// $component->off($eventName, $handler);
Copy after login

The above is the detailed content of What is the difference between yii1.1 and yii2.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