laravel门面门面访问的工作

问题描述 投票:1回答:1

我所看到的一样,他们使用的立面和注册评审员对一些类。

use Illuminate\Support\Facades\Facade;

/**
 * @see \Collective\Html\FormBuilder
 */
class FormFacade extends Facade {

    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor() { return 'form'; }

}

它只是从laravel包,它只是返回门面拍摄,但实际上是回报的形式做了什么?

php laravel laravel-5 laravel-5.1 laravel-facade
1个回答
1
投票

Laravel外墙是一种“网关”的服务。它的“语法糖”,使代码看起来更具可读性。所以,如果你不喜欢的东西:

Form::open(array('route' => 'route.name'));

什么你实际上做的是要求解决名为“形式”,因为它的主要配置的服务提供商的应用程序。这是另一种方式,它可以做:

app('form')->open(array('route' => 'route.name'));

在现实中,你可以做旧的方式方法太多,但DI(依赖注入)是一个伟大的工具:

// Rough example without the actual parameters
$form = new Illuminate\Html\FormBuilder();
$form->open(array('route' => 'route.name'));
© www.soinside.com 2019 - 2024. All rights reserved.