Home > Article > PHP Framework > What is the difference between yii1.1 and yii2.0
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.
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 = in the view file. Starting from PHP 5.4, it will always be recognized and legal, no matter what the setting of short_open_tag is, it can be used safely.
SPL Classes and Interfaces
Delayed Static Binding
Date and Time
Traits
intl Yii 2.0 uses PHP extension intl to support internationalization related functions.
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:
) 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 ObjectYii 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);
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);
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!