How to use ActiveRecord mode in yii2, yii2record_PHP tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.