<?php namespace app\index\controller; //use \think\facade\Request; use \think\Request; /** * Class Demo3 * @package app\index\controller * 正常狀況下,控制器不依賴於父類Controller.php * 推薦繼承父類,能夠很方便的使用在父類中封裝好的一些方法和屬性 * Controller.php沒有靜態代理 * 控制器中的輸出,字符串所有用return返回,不要用echo * 若是輸出的是複雜類型,咱們能夠用dump()函數 * 默認輸出的格式爲html,能夠指定爲其它格式:json */ class Demo3 extends \think\Controller { public function test() { //return 'www.php.cn'; //dump(Request::get());//靜態代理 //dump((new Request())->get());//正常使用 //dump($request->get());//依賴注入 return json_encode($this->request->get()); } }