我见过这样的类,它们使用facade并在acessor上注册一些东西。
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包中提取出来的,它只是返回facade,但是这个返回形式到底做了什么呢?
发布于 2015-12-10 01:23:24
Laravel的外观是一种服务的“门户”。它是“语法糖”,使代码看起来更具可读性。所以如果你做了一些类似的事情:
Form::open(array('route' => 'route.name'));您实际要做的是请求应用程序解析配置了名称“form”作为其关键字的服务提供商。这是另一种可以做到的方法:
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'));https://stackoverflow.com/questions/34185022
复制相似问题