4
我試圖擴展Laravel 5核心類。我想實現的是我可以有自定義的url生成器例如。 URL :: test()將生成自定義鏈接。Laravel 5擴展核心類
到目前爲止,我有:
- 創建應用程序/ Acme的/ lib文件夾
添加的應用/ Acme的/ lib目錄路徑composer.json類映射
"autoload": { "classmap": [ .... app/Acme/lib ] }
創建自定義UrlGenerator類在Acme/lib/CustomUrlGenerator.php中
<?php namespace App\Acme\lib; use \Illuminate\Routing\UrlGenerator; class CustomUrlGenerator extends UrlGenerator { public function test() { return $this->to('/test'); } }
創建的服務提供商的應用程序/ Acme的/ lib目錄/ CustomUrlServiceProvider.php
<?php namespace App\Acme\lib; use \Illuminate\Routing\RoutingServiceProvider; class CustomUrlServiceProvider extends RoutingServiceProvider { public function boot() { App::bind('url', function() { return new CustomUrlGenerator( App::make('router')->getRoutes(), App::make('request') ); }); parent::boot(); } }
- 在app /配置/ app.php
- 運行作曲家轉儲自動加載
註冊服務提供商
現在,當我跑{!!即時通訊404(每個路線)
Sorry, the page you are looking for could not be found.
NotFoundHttpException in /vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php line 143:
有什麼,我失蹤了嗎? 非常感謝您的任何幫助..
是的,我有固定的(非常感謝)+根據這個答案固定的自定義服務提供商http://stackoverflow.com/a/20520861/4437438,現在它正常工作 – SirInfant
喜歡有幫助 – Zl3n