The ActiveRecord mode is used in yii2record. In yii2, the ActiveRecord mode is used. In this example, yii2record describes how to use the ActiveRecord mode in yii2. For your reference, see: 1. use the Active Record mode in db. ph yii2, yii2record
This example describes how to use the Active Record mode in yii2. We will share this with you for your reference. The details are as follows:
1. configure the corresponding database information in db. php:
return [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yii2basic', 'username' => 'root', 'password' => '', 'charset' => 'utf8',];
2. use the gii module to automatically generate the corresponding code (access link http: // localhost/basic/web/index. php? R = gii ):
Use ModelGenerator and CURD Generator to automatically generate the corresponding model code and add, delete, modify, and query code.
3. when the tables in the database need to be modified, you can use migration:
Execute the command in the project:./yii migrate/create "custom name"
A new folder migrations is generated in the project to open the files in the folder:
class m150225_022640_modify_book_table extends Migration{ public function up() { $this->addColumn("book", "book_desc", yii\db\mssql\Schema::TYPE_TEXT); } public function down() { echo "m150225_022640_modify_book_table cannot be reverted.\n"; return false; }}
Use the command:./yii migrate in the command line to execute the up function in the script.
Use the command:./yii migrate/down in the command line to execute the down function in the script.
I hope this article will help you design PHP programs based on the Yii Framework.
Articles you may be interested in:
- Yii2 uses the Bootbox plug-in to implement custom pop-up windows
- YII2 framework (IV) extension plug-in yii2-kartikgii from scratch
- YII2 framework (III) extension plug-in yii2-gird from scratch
- YII2 framework from scratch (2) Install extension plug-ins through Composer
- Use the drop-down menu to automatically search for yii-widget-select2 instance analysis in the yii2 framework
- Example of Activeform component usage in YII2.0
- How to add a verification code in yii2
- Method for referencing the date plug-in yii2-date-picker in bootstrap in the Yii2 framework
The method of using Record mode. yii2record this article describes how to use the Active Record mode in yii2. For your reference, the details are as follows: 1. in db. ph...