Laravel Illuminate\Support\Facades\Input

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26972711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:25:56  来源:igfitidea点击:

Laravel Illuminate\Support\Facades\Input

phplaravelnamespaceslaravel-facade

提问by user2722667

I am new to Laravel and checking out some sample code.

我是 Laravel 的新手,正在查看一些示例代码。

In a controller I see this:

在控制器中,我看到了这个:

<?php

use Illuminate\Support\Facades\Input;

class RegistrationController extends \BaseController {

public function __construct()
{
    $this->beforeFilter('guest');
}

Why do I have to use the "use Illuminate\Support\Facades\Input;" ?

为什么我必须使用“ use Illuminate\Support\Facades\Input;”?

Cant I just use eg Input::get(); like I do in my route file?

我不能只使用例如 Input::get(); 就像我在路由文件中所做的那样?

回答by Marcin Nabia?ek

You don't have to use importing namespaces (you don't need to add use Illuminate\Support\Facades\Input;) here.

您不必use Illuminate\Support\Facades\Input;在此处使用导入命名空间(您不需要添加)。

You can accesss Input facade, using Input::get('something')as long as your controller is in global namespace. Otherwise you need to use \Input::get('something')or add use Inputafter <?php.

Input::get('something')只要您的控制器在全局命名空间中,您就可以访问 Input 外观。否则,你需要使用\Input::get('something')或添加use Input之后<?php

回答by itachi

<?php

use Illuminate\Support\Facades\Input;

class RegistrationController extends \BaseController {

public function __construct()
{
    $this->beforeFilter('guest');
}

this controller is in global namespace. so you don't need to use use Illuminate\Support\Facades\Input;you can directly call Input::get('foo');

此控制器位于全局命名空间中。所以你不需要使用use Illuminate\Support\Facades\Input;你可以直接调用Input::get('foo');

<?php namespace Foo; //<---- check the namespace

    use Input;

    class RegistrationController extends \BaseController {

    public function __construct()
    {
        $this->beforeFilter('guest');
    }

here you can write either, use Inputor \Input::get('foo')while calling.

在这里你可以一次,use Input\Input::get('foo')同时呼吁。