栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > Laravel

Laravel Facades

Laravel 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力
以下是在Laravel创建 Facade 的步骤:
  • 第1步 - 创建PHP类文件
  • 第2步 - 绑定类到服务提供者
  • 第3步- 注册服务提供者到 Configapp.php 作为供应者
  • 第4步- 创建类,这个类是扩展lluminateSupportFacadesFacade
  • 第5步- 注册第4点到 Configapp.php 作为别名
Facade类参考 Laravel附带许多Facades。下面是内置的Facades类引用。
Facade 服务容器绑定
App IlluminateFoundationApplication app
Artisan IlluminateContractsConsoleKernel artisan
Auth IlluminateAuthAuthManager auth
Auth (Instance) IlluminateAuthGuard
Blade IlluminateViewCompilersBladeCompiler blade.compiler
Bus IlluminateContractsBusDispatcher
Cache IlluminateCacheRepository cache
Config IlluminateConfigRepository config
cookie IlluminatecookiecookieJar cookie
Crypt IlluminateEncryptionEncrypter encrypter
DB IlluminateDatabaseDatabaseManager db
DB (Instance) IlluminateDatabaseConnection
Event IlluminateEventsDispatcher events
File IlluminateFilesystemFilesystem files
Gate IlluminateContractsAuthAccessGate
Hash IlluminateContractsHashingHasher hash
Input IlluminateHttpRequest request
Lang IlluminateTranslationTranslator translator
Log IlluminateLogWriter log
Mail IlluminateMailMailer mailer
Password IlluminateAuthPasswordsPasswordBroker auth.password
Queue IlluminateQueueQueueManager queue
Queue (Instance) IlluminateQueueQueueInterface
Queue (base Class) IlluminateQueueQueue
Redirect IlluminateRoutingRedirector redirect
Redis IlluminateRedisDatabase redis
Request IlluminateHttpRequest request
Response IlluminateContractsRoutingResponseFactory
Route IlluminateRoutingRouter router
Schema IlluminateDatabaseSchemaBlueprint
Session IlluminateSessionSessionManager session
Session (Instance) IlluminateSessionStore
Storage IlluminateContractsFilesystemFactory filesystem
URL IlluminateRoutingUrlGenerator url
Validator IlluminatevalidationFactory validator
Validator (Instance) IlluminatevalidationValidator
View IlluminateViewFactory view
View (Instance) IlluminateViewView
示例 第1步- 执行以下命令创建一个叫作 TestFacadesServiceProvider 的服务提供者。
php artisan make:provider TestFacadesServiceProvider
第2步 - 成功执行后,您会收到以下输出 -



第3步 - 在“App/Test”创建一个名为 “TestFacades.php”的类

App/Test/TestFacades.php


	
		第4步 - 在“App/Test/Facades”创建一个名为“TestFacades.php” 的一个Facade类。
	
	

App/Test/Facades/TestFacades.php


	
		第5步- 在“App/Test/Facades”创建一个名为 “TestFacadesServiceProviders.php”的一个Facade类。
	
	

App/Providers/TestFacadesServiceProvider.php


	
		第6步 - 在文件 config/app.php 中添加一个服务提供者如图所示如下图。
	
	

config/app.php




第7步 - 在文件 config/app.php 中添加别名如图所示如下图。

config/app.php




'TestFacades' => AppTestFacadesTestFacades::class, 
第8步 - 添加以下行到文件 - app/Http/routes.php

app/Http/routes.php

Route::get('/facadeex', function(){
   return TestFacades::testingFacades();
});
第9步 - 访问以下网址测试 Facade

http://localhost:8000/facadeex

第10步 - 访问URL后,您会收到以下输出 -



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/9865.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号