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.
Yii 2.0 requires PHP 5.4 or higher, which is a huge improvement over the PHP 5.2 required by Yii 1.1.
1. The application instance directly uses global named variables to access: $app without calling app().
2. A significant change in the view layer of Yii2 is the introduction of view classes, which makes the implementation of the MVC pattern more complete. Correspondingly, the relevant presentation layer auxiliary classes are managed by the new view class. For example, theme: Yii::app()->theme->baseUrl should be updated to Yii::$app->view-> theme->baseUrl, or $this->theme->baseUrl.
3. Yii2 introduces the concept of resource packages, and the way of resource reference has changed greatly.
There are two ways to introduce resources, one is through the AppAsset class in the assets directory, and the other is through a registration method similar to Yii1.
Yii::app()->getClientScript() method is no longer available. For example, if you want to dynamically register a JS script file in the page, the changes are as follows:
Yii::app() ->getClientScript()->registerScriptFile('...') is changed to Yii::$app->view->registerJsFile('...'),
or $this- >registerJsFile('...').
If you are a beginner, it is recommended to learn yii2 directly.
PHP Chinese website has a large number of free Yii introductory tutorials, everyone is welcome to learn!
The above is the detailed content of What is the difference between yii1 and yii2. For more information, please follow other related articles on the PHP Chinese website!