方法一:
<?php
namespace app\index\controller;
class Index{
public function index()
{
$request = request();
dump($request);
}
}
?>
方法二:
<?php
namespace app\index\controller;
use think\Request;
class Index{
public function index()
{
$request = Request::instance();
dump($request);
}
}
?>
方法三:
<?php
namespace app\index\controller;
use think\Request;
class Index{
public function index(Request $request)
{
dump($request);
}
}
?>
在我看来可以使用方法一也可以使用方法二,但是为了方便和可行性更高我建议大家直接使用注入对象的方式(方法三)来进行编写,在我们以后的开发中使用这种方法可能会让我们的开发变得更简单。