Because Yii 2.0 is a complete rewrite of the framework, upgrading from version 1.1 is not trivial.
There are many differences between Yii version 2.0 and 1.1, because Yii is completely rewritten for 2.0.
We recommend you read through this guide before performing the upgrade. In this chapter, we will
As a result, upgrading from version 1.1 is not as trivial as upgrading between minor versions. In this chapter,
summarize the major differences between 1.1 and 2.0. We hope this will make it easier for you
we will summarize the major differences between the two versions.
to upgrade from Yii 1.1 and quickly master Yii 2.0 based on your existing Yii knowledge.
Please note that Yii 2.0 introduces many new features which are not covered in this summary. It is highly recommended
that you read through the whole definitive guide to learn about these features. Chances could be that
some features you previously have to develop by yourself are already part of the core code now.
Installation
------------
Yii 2.0 fully embraces [Composer](https://getcomposer.org/), a de facto PHP package manager. Installation
of the core framework as well as extensions are all installed through Composer. Please refer to
the [Starting from Basic App](start-basic.md) chapter to learn how to install Yii 2.0. If you want to
create new extensions or turn your existing 1.1 extensions into 2.0, please refer to
the [Creating Extensions](extend-creating-extensions.md) chapter.
Namespace
Namespace
...
@@ -121,82 +134,35 @@ More on path aliases can be found in the [Path Aliases](basic-aliases.md) chapte
...
@@ -121,82 +134,35 @@ More on path aliases can be found in the [Path Aliases](basic-aliases.md) chapte
Views
Views
-----
-----
Yii 2.0 introduces a [[yii\web\View|View]] class to represent the view part of the MVC pattern.
The most significant change about views is that `$this` in a view no longer refers to
It can be configured globally through the "view" application component. It is also
the current controller or widget. Instead, it refers to a *view* object which is a new concept
accessible in any view file via `$this`. This is one of the biggest changes compared to 1.1:
introduced in 2.0. The *view* object is of class [[yii\web\View]] which represents the view part
**`$this` in a view file no longer refers to the controller or widget object.**
of the MVC pattern. In you want to access the controller or widget in a view, you should use `$this->context`.
It refers to the view object that is used to render the view file. To access the controller
or the widget object, you have to use `$this->context` now.
For partial views, the [[yii\web\View|View]] class now includes a `render()` function. This creates another significant change in the usage of views compared to 1.1:
To render a partial view within another view, you should use `$this->render()` now.
**`$this->render(...)` does not output the processed content; you must echo it yourself.**
And you have to echo it explicitly because the `render()` method will return the rendering
result rather than directly displaying it. For example,
```php
```php
echo$this->render('_item',['item'=>$item]);
echo$this->render('_item',['item'=>$item]);
```
```
Because you can access the view object through the "view" application component,
Besides using PHP as the primary template language, Yii 2.0 is also equipped with official
you can now render a view file like the following anywhere in your code, not necessarily
support for two popular template engines: Smarty and Twig. The Prado template engine is no longer supported.
in controllers or widgets:
To use these template engines, you need to configure the `view` application component by setting the
[[yii\base\View::$renderers|View::$renderers]] property. Please refer to the [Template Engines](tutorial-template-engines.md)