Home> PHP Framework> YII> body text

The difference between yii1 and yii2

王林
Release: 2020-02-20 16:02:00
Original
3647 people have browsed it

The difference between yii1 and yii2

1. Quickly distinguish yii1 and yii2

yii1:

Yii::app()
Copy after login

yii2:

Yii::$app
Copy after login

2. When the controller is called Difference

For example: the controller file name is UserGroupController.php

The function is actionIndex

(recommended tutorial:yii framework)

yii1:

index.php?r=userGroup/index&page=1
Copy after login

yii2:

index.php?r=user-group/index&page=1
Copy after login

The directory under the corresponding view is also similar. It needs to be named user-group.

3. Use the database

For example, query a record with user_id

yii1:

User::model()->find('user_id=:user_id',[':user_id'=>$user_id]);
Copy after login

yii2:

User::find()->where('user_id=:user_id',[':user_id'=>$user_id])->one();
Copy after login

Query many Records:

yii1:

User::model()->findAll('status=:status',[':staus'=>$status]);
Copy after login

yii2:

User::find()->where('status=:status',[':staus'=>$status])->all();
Copy after login

In addition, yii2 also provides the asArray() method, and the direct query result is an array:

User::find()->where('status=:status',[':staus'=>$status])->asArray()->all();
Copy after login

For more programming-related content, please pay attention to theIntroduction to Programmingcolumn on the php Chinese website!

The above is the detailed content of The difference between yii1 and yii2. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!