Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Yii2 foreground and background Separation and example Analysis of migrate usage

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you the Yii2 front and background separation and the use of migrate example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Generally speaking, the following three are more commonly used:

A. share a verification system and a data table.

B, two verification systems and share a data table.

C, two verification systems and two data tables.

Yii2 Premium Edition defaults to type A, that is, the data table is the same, and one side logs in / out, and the other side also logs in / out. I feel that this structure is more suitable for the forum, and the administrator also needs to have the same functions as members, and the table field is basically the same. (personal view, after all, there are not many contacts, and different background topics have been searched on the Internet, but there are few detailed discussions.) The foreground and background can be distinguished by fields, permissions, and so on. What we are going to do is C type, such as some e-commerce websites, the backstage administrator and the foreground member function is too different, and the table field difference is also big, so the verification system is different, and it is better to put two data tables. As for type B is a simplified version of type C, if C can be set, B is the same.

Let's first create an admin table to store administrator data, but members still use the original user table. Here we use the migrate of yii to create it, which is mentioned in the Yii2 initialization chapter. Here we will describe it in more detail:

1, yii2 version 2.07 before the command, you can create a php file in the console/migrations directory, and then write and create table statements under this file, and so on.

Yii migrate/create admin

2. After yii2 version 2.07, more detailed categories have been added. For example, I have created the admin table, but one status field is missing. Then I can directly use the following command to generate a file that only adds fields.

Yii migrate/create add_column_to_admin-fields=status:int (10): nontNull

Generate:

Use yii\ db\ Migration;class extends Migration {const TBL_NAME ='{{%}}'; public function up () {$tableOptions = null;if ($this- > db- > driverName = = 'mysql') {$tableOptions =' CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB COMMENT=';} $this- > createTable (self::TBL_NAME, ['= > $this- >)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report