Home  >  Article  >  Backend Development  >  php的类的方法里面传递一个类名求教,laravel

php的类的方法里面传递一个类名求教,laravel

WBOY
WBOYOriginal
2016-06-06 20:23:261678browse

使用laravel时,看到有这样的用法:

<code class="php">    public function add(Request $request)
    {
        $name = $request->input('user_name');
    }</code>

请问上述function里面的参数是什么意思啊?

回复内容:

使用laravel时,看到有这样的用法:

<code class="php">    public function add(Request $request)
    {
        $name = $request->input('user_name');
    }</code>

请问上述function里面的参数是什么意思啊?

这里的 $request 参数是 Illuminate\Http\Request ,通过依赖注入传递给Controller。

在Laravel中Controller都可以在顶部use Illuminate\Http\Request 后,在参数里面使用 Request。

而 Request 包含了客户端发送过来的请求内容。

对于array,class类型的函数/方法参数,从php5 开始php是要求明确参数类型的,你这里是类类型的参数

我这个回答不正确,请参考下面评论@vimac的回答

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn