This article was written 1604 days ago and last revised 1390 days ago. Some of the information may be outdated.

Fastadmin Pit Treading Diary - 1. Initial plug-in development

Fastadmin is a home-made out of the box background management system based on thinkPHP5 and Bootstrap. It is suitable for rapid development of the background. It integrates the responsive design method of Bootstrap and an excellent member permission system. It has a community of thinkPHP to support its development. It is very easy to use. However, there will be pitfalls when it is easy to use.

Why use Fastadmin

At the beginning, the CMS background system in the "php and mysql program design" of the telecast podcast in the library was built by myself. At that time, I thought it was very powerful, but there was always a problem that could not be solved, that is, the permission system. People like me do not know this, and no one has taught me. They just want to know whether there is a wheel that can be used directly.

Find some interesting ones on the Internet

The first two are based on the front-end technology stack, Vue+node, and the last two are based on php

I thought about it for two days. I still haven't done the first two. It's too complicated and takes too long to get started. In addition, I have to use pm2 to hang up. I have to manually configure the old server Apache Of vhost , which is too troublesome, so I chose php

Then select the one that is more suitable for development Fastadmin , his advantages are:

  1. Own permission management
  2. Can be used Php think CURD command Automatically generate MVC code
  3. thinkphp Good ecology
  4. Self contained bootstrap-table
  5. There is also a store. You can download some plug-ins online to use

So I used this

But I strongly recommend it Phalapi Framework This framework is really excellent for writing APIs. It is really super simple to get started, and it will automatically generate API documents, which is great.

Getting Started Fastadmin

MVC architecture

Fastadmin be based on Thinkphp5 , so the classic MVC (Model View Controller) architecture , each layer performs its own duties and does not interfere with each other,

Controller Controller : Be responsible for dispatching tasks and processing tasks, providing data rendering to the view layer, and sending read database instructions to the model layer

Model layer : Responsible for reading and writing the database and basic processing

View view layer : It is responsible for the part that users see. It is usually an html file. The controller renders the data to achieve the picture that our browser sees.

After understanding this, you can come to the official quick start guide

express setup

It is strongly recommended to download the complete package directly instead of using the command line to install it. Because various package management software will have various problems, it is convenient to decompress the complete package directly, and then mount it on the web server, locate it in the public folder and install it normally

To get started quickly, you should first read the study manual

To get started with this framework, first read at least the first one. Because the official documents are not very detailed, we have to see thinkphp5

Thinkphp5 Quick Start This can be taken advantage of pneumonia for free now, and will become 20 yuan later, but I have downloaded his Mobi version here to see how it can be uploaded

Thinkphp5 Complete Development Manual

Fastadmin Framework Development Guide

Fastadmin Plug in Development Guide

Generate Plug in

The fastadmin plug-in is a simple integration package, which can quickly deploy the required functions. In order to achieve rapid migration, you should decide to use plug-ins instead of native development

Direct execution

 Php think addon - a<your plugin name>- c create #If PHP fails like me, remember to execute it with PHP in the corresponding web server, as shown below /Applications/XAMPP/xampfiles/bin/php think addon - a<your plug-in name>- c create

Then, the plug-in file will appear in the addons folder. After the initial configuration, the hole will come

Pit 1 - plug-in not registered - menu not found

The plug-in file in addons is not executed at all! Because the above command to generate plug-ins will not help you register plug-ins

You must package the zip and then install it offline. After overwriting the application, it will be executed in the application file

This pit leads me to fail to locate the reason why the sidebar does not appear

After the plug-in is generated, the configuration is completed, the package is completed, the original plug-in is uninstalled, the formal registration is completed after the plug-in is installed again, and it can be accessed. Later, it needs to be developed in the application, and then it needs to be thrown back to adds, and the package is completed

In addition, when packaging, do not directly compress the folder, but compress all the files under the folder into zip. Then install offline, so that it will not appear Plug in configuration file not found (code: 0) About

Automatically generate menus

Use the command to automatically generate the MVC framework and generate the bootstrap table for management

It is enough to read this article. It is required to create a table first

FastAdmin Usage - Basic Usage

The following is an excerpt

Use the command line to create crud procedures:

The official document details the process of creating crud. The most frequently used command in the project is the creation command. First, we create a test table in the database (crud creation must be based on the table), enter the cmd command line, enter the fastadmin folder, and enter the creation command.

Here is a description. The secondary menu I enter here will automatically create a folder student. If the secondary menu is not required, enter the controller name directly. In addition, if the current table already has a corresponding controller, an error will be prompted and the creation fails. At this time, we need to add -- force=true after the command to create more controllers. Other commands and problems are described in the official documents.

At this time, a new crud is created. Next, we can find the relevant code in the directory

Controller - application admin controller student Student.php

Model layer - application admin model Sludent.php

View layer - application admin view student student

We found that this is the MVC pattern we are familiar with. Because it is based on the secondary development of tp5, it is an MVC architecture, and all the codes of tp5 can be used.

Here are some other files:

Validation rules - application admin validate Student.php

Language pack - application admin lang en cn student student.php

Js file -- public assets js backend student student.js

These are the files we need to change in the project. When we visit the background, we find that there is no new student controller we have generated

This is because we need to use the command line to generate the menu for the corresponding controller

When we refresh the page, we will find that the menu has been generated and can be accessed.

We can also manage the menu bar directly through rule management

You can directly modify the url, menu name, icon, weight (operation layout), and whether to generate a menu. It is explained here that a corresponding rule needs to be added whenever a method is added in the code. Otherwise, when a user changes, the method cannot be used and an error will be reported. The generated rule has a rule table in the database that can be viewed directly, Users can be grouped in role groups, and then different rules can be assigned to users in different groups to control the permissions of user groups.

We find that the page is generated for us directly here, and the specific operation of the page through code will be written in the following blog.

Here's a description of its url,

If you have experience in tp development, you can know that the front is the corresponding controller, while the later parameter ref=addtabs does not know what it means. We can remove this parameter and access it

It can be seen that there is no menu bar on the left side, so this parameter is used to generate the menu bar. The specific implementation process is encapsulated in the framework, so you don't need to care.

In addition, it is also stated in the official document that if the core js, css or other files in the framework are changed, they can only work in the production environment with one click packaging. Other commands and directory architecture are also stated in the official document

Method of creating menu in plug-in

The above method is to directly create a menu in the application. We are plug-in development and have to do it ourselves. We execute

 Php think crud - t<corresponding data table>- c<plug-in name>/<plug-in controller> #For example, if I create the Users controller under the mypchelper plug-in according to my fa_pc_users table, enter /Applications/XAMPP/xamppfiles/bin/php think crud -t fa_pc_users -c mypchelper/Users #Note that this command is executed several times for several tables. When creating a data table, it is extremely necessary to make naming, field selection and annotation according to official requirements

After execution, after the menu is configured normally, we can access the corresponding table and directly set the bootstrap table

The next article introduces the multi table query of bootstrap table in Fastadmin and the use of the format of bootstrap table

reference material

  1. FastAdmin Usage - Front End
  2. Fastadmin multi table association query
  3. Fastadmin founder replies to multi table query
  4. FastAdmin Multi table Associated Query