Blogger Information
Blog 18
fans 1
comment 0
visits 16083
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkPHP6框架基础知识
空瓶子
Original
646 people have browsed it

关于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. }
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!