Home  >  Article  >  PHP Framework  >  The difference between yii1 and yii2

The difference between yii1 and yii2

王林
王林Original
2020-02-20 16:02:003704browse

The difference between yii1 and yii2

1. Quickly distinguish yii1 and yii2

yii1:

Yii::app()

yii2:

Yii::$app

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

yii2:

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

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]);

yii2:

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

Query many Records:

yii1:

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

yii2:

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

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();

For more programming-related content, please pay attention to the Introduction to Programming column 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!

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