1.传统调用
~~~
namespace app\index\Controller;
use think\Request;
class Index{
public function hello(){
$request = Request::instance();
echo $request->url();
}
}
~~~
~~~
$request->url(true);
$request->domain();
$request->baseFile();
$request->root();
$request->pathinfo();
$request->ext();
~~~
2.继承Controller [推荐 ]
~~~
namespace app\index\Controller;
use think\Controller
class Index extends Controller{
public function index(){
$this->request->url();
}
}
~~~
3.自动注入
~~~
namespace app\index\Controller;
use think\Request;
class Index{
public function index(Request $request){
echo $request->url();
}
}
~~~
4.助手函数
~~~
namespace app\index\Controller;
class Index{
public function hello(){
echo request()->url():
return 'hello';
}
}
~~~
其他还有
~~~
$request->method();
$request->module();
$request->controller();
$request->action();
$request->param();
$request->param('name');
$request->get('name');
$request->post('name');
~~~