<?php
namespace app\index\controller;
use think\Controller;
//靜態(tài)代理
//use think\facade\Request; //導(dǎo)入請(qǐng)求對(duì)象的靜態(tài)代理
use think\Request;
/**
Class Demo3
@package app\index\controller
正常情況下,控制器是不依賴于父類controller.php
推薦繼承父類,可以很方便的使用在父類中封裝好的一些方法和屬性
Controller.php 沒(méi)有靜態(tài)代理
控制器中的輸出,字符串全部用return 返回,不要用echo
如果輸出的是復(fù)雜類型,可以用 dump() 函數(shù)
默認(rèn)輸出為html,可以指定為其他格式:json
1.傳統(tǒng)的new Request
2.靜態(tài)代理: think\Facade\Request
3.依賴注入: Request $request
-
4.父類Controller中的屬性
this->request;
*/
class Demo3 extends Controller
{
//依賴注入
public function test(\think\facade\Requestrequest::get());
}public function test2()
{
//通過(guò)繼承Controller父類的request屬性
dump($this->request->get());
}
}