创建静态方法:
在ThinkPHP6中,可以在控制器中创建静态方法,具体步骤如下:
- 在控制器中创建一个静态方法,例如:
public static function test(){
echo 'This is a static method!';
}
- 在路由中定义一个路由规则,例如:
Route::get('test', 'Index/test');
- 在浏览器中访问该路由,例如:
http://localhost/test
- 在浏览器中就可以看到输出的内容了,例如:
This is a static method!
引用静态方法:
在ThinkPHP6中,可以通过类名来引用静态方法,具体步骤如下:
- 在控制器中创建一个静态方法,例如:
public static function test(){
echo 'This is a static method!';
}
- 在其他控制器或模型中引用该静态方法,例如:
Index::test();
传值:
在ThinkPHP6中,可以通过参数来传递值,具体步骤如下:
- 在控制器中创建一个静态方法,例如:
public static function test($name){
echo 'Hello, '.$name.'!';
}
- 在路由中定义一个路由规则,例如:
Route::get('test/:name', 'Index/test');
- 在浏览器中访问该路由,例如:http://localhost/test/ThinkPHP6
- 在浏览器中就可以看到输出的内容了,例如:
Hello, ThinkPHP6!