博客列表 >thinkPHP6框架基础知识

thinkPHP6框架基础知识

空瓶子
空瓶子原创
2021年03月11日 17:02:46645浏览

关于thinkPHP的基础操作

请求对象

  • 构造方法注入
    1. class Index
    2. {
    3. public function __construct(Request $request)
    4. {
    5. $this->request = $request;
    6. }
    7. public function index()
    8. {
    9. return $this->request->param('id');
    10. return 'hello world';
    11. }
    12. }
  • 操作方法注入

    1. class Index
    2. {
    3. public function index(Request $request)
    4. {
    5. dump($request->param()) ;
    6. }
    7. }
  • 静态调用

  1. use think\facade\Request;
  2. //静态调用
  3. class Index
  4. {
  5. public function index(Request $request)
  6. {
  7. return Request::param('name');
  8. }
  9. }

  • 助手函数
    request()、input()、view()、json()
  1. //助手函数
  2. class Index
  3. {
  4. public function index(Request $request)
  5. {
  6. dd(request()->param());
  7. }
  8. }
  • view()
    1. class Index
    2. {
    3. public function index(Request $request)
    4. {
    5. $name = 'admin';
    6. return view('welcome',['name'=>$name]);
    7. }
    8. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议