Home  >  Article  >  PHP Framework  >  What is the difference between yii1 and yii2

What is the difference between yii1 and yii2

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-12-07 16:28:594002browse

What is the difference between yii1 and yii2

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!

Statement:
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