How to understand the application public files in thinkphp5?

all controllers of my background module admin, need operation authentication, or build operation menus, or other common operations

on the premise of ignoring the intermediate key:

my previous way of writing is to write a "master" controller common, and then all the controllers inherit the master controller and do these operations in the master. I always think this is a lame way to write!

I don"t quite understand the application common files in object-oriented. Of course, the custom function like common.php in thinkphp doesn"t count.

ask for analysis.

Mar.05,2021

I may not be right, but I want to communicate with you. I think the application public file includes the front file and the back-end file, and the back-end is some common methods of the controller, such as how to delete and change it, and the front paragraph is some


.

give an example
Common module

public function checkmsg ($phone,$msg);{
    if(){
            returun true;
    }else{
         throw new Exception("");
    }
}

A registration module of the home module uses the CAPTCHA function

public function login($msg,$phone,$password){
    checkmsg($phone,$msg);
    //
}

admin module A function that needs to verify the identity of the administrator through the mobile phone number

public function checkauthority($msg,$phone){
     checkmsg($phone,$msg);
    //XXX
}

so you can share one thing


this is the most commonly used
BaseController
followed by
AdminController extend BaseController

it is obvious that the landlord does not want it

then have a little "Design pattern"

We can inject dependencies into the stack first and trigger them when we want to use them.

can be used in both tp3.2 and tp5

use TP5

here
amespace app\index\behavior;

use think\Request;

class Test 
{
    public function run(Request $request, $params)
    {
        // 
    }
}

define the tags.php file under the application directory or the module directory to uniformly define the behavior. The format is as follows

return [
    //index
    'app_init'=> [
        'app\\index\\behavior\\CheckAuth',
    ],
]

execute behavior directly

//  app\index\behavior\CheckAuthrun params
$result = Hook::exec('app\\index\\behavior\\CheckAuth',$params);
For more information, please see hooks and behaviors: https://www.kancloud.cn/manua.

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31c3c-e30d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31c3c-e30d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?