2014-04-14 51 views
0

我知道這個問題lil有點舊,但我仍然找不到合適的解決方案。我一直在搜索互聯網幾天,並嘗試幾種解決方案,檢查我的文件路徑,更新composer.json,然後dump-autoload它,但仍然沒有運氣。我仍然收到以下錯誤:Laravel ReflectionException錯誤:庫不存在

ReflectionException 
Class Cribbb\Storage\User\EUserRepository does not exist 

這是我的代碼。

控制器(應用程序/控制器/ UsersControllers.php):

<?php 

use Cribbb\Storage\User\IUserRepository as User; 

class UsersController extends \BaseController { 

    /** 
    * Display a listing of the resource. 
    * 
    * @return Response 
    */ 

    public function __construct(User $user) 
    { 
     $this->user = $user; 
    } 
?> 

接口(LIB/Cribbb /存儲/用戶/ IUserRepository.php):

<?php 

namespace Cribbb\Storage\User; 

interface IUserRepository{ 

    public function all(); 
    public function find($id); 
    public function create($input); 
} 

?> 

的信息庫(LIB /Cribbb/Storage/User/EUserRepository.php):

<?php 

namepsace Cribbb\Storage\User; 

use User; 

class EUserRepository implements IUserRepository 
{ 

    public function all() 
    { 
     return User::all(); 
    } 

    public function find($id) 
    { 
     return User::find($id); 
    } 

    public function create($input) 
    { 
     return User::create($input); 
    } 



} 

?> 

的服務提供商(LIB/Cribbb /存儲/ StorageServiceProv ider.php):

<?php 

namespace Cribbb\Storage; 

use Illuminate\Support\ServiceProvider; 

class StorageServiceProvider extends ServiceProvider { 

    public function register() 
    { 
    $this->app->bind(
     'Cribbb\Storage\User\IUserRepository', 
     'Cribbb\Storage\User\EUserRepository' 
    ); 
    } 

} ?> 

我也包括在應用程序/配置/ app.php如下服務提供商:

'providers' => array(
... 
'Cribbb\Storage\StorageServiceProvider' 
); 

和我添加的應用/ lib中composer.json:

"autoload": { 
     "classmap": [ 
      "app/commands", 
      "app/controllers", 
      "app/models", 
      "app/database/migrations", 
      "app/database/seeds", 
      "app/tests/TestCase.php", 
      "app/lib" 
     ] 
    } 

關於這個的奇怪部分是,雖然IUserRepository和EUserRepository位於同一個文件夾中,但Laravel僅檢測IUserRepository。看來無法找到EUserRepository。 我錯過重要的事情嗎?任何建議傢伙?

+0

你有沒有複選文件名? –

+0

是的。我已經仔細檢查過它們。我甚至創建了一個新文件,用不同的名稱命名它們,並將其與EUserRepository一起放入同一個文件夾中,並將其綁定到服務提供者中。和拉拉維爾仍然拋出同樣的錯誤。 – under5hell

+0

嗨菲利普!爲什麼不將該文件夾註冊爲PSR-0或PSR-4? – hannesvdvreken

回答

1
namepsace Cribbb\Storage\User; 

它應該是命名空間嗎?

編輯

資源庫(LIB/Cribbb /存儲/用戶/ EUserRepository.php)有一個錯字:

<?php 

namepsace Cribbb\Storage\User; 

因爲你沒有使用自動加載它只是作爲加載類\EUserRepository 。 (根範圍)

+0

不,不應該。我把StorageServiceProvider.php放在lib/Cribbb/Storage /中,而我的倉庫和接口放在lib/Cribbb/Storage/User中。無論如何,我試過你的建議。將命名空間更改爲Cribbb \ Storage \ User,laravel扔我「找不到serviceprovider」錯誤。然後我將文件移動到lib/Cribbb/Storage/User,在app/config/app.php中更新'providers'aaray,dump-autoload,但仍然沒有運氣。 :( – under5hell

+0

你在lib/Cribbb /存儲/用戶/ EUserRepository.php – veelasky

+2

(@veelasky你可以編輯答案是一個更具體的回答問題(可能提到文件,它是一個事實)) – alexrussell

相關問題