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!