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..