2013-12-08 47 views
0

我必須將命名空間合併到我的項目中,因爲我需要使用名爲「事件」的模型,以避免Laravel使用預定義的「事件」時出錯。命名空間添加後的錯誤。無法訪問模型

Composer.json:

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

"psr-0": { 
    "App": "app/models/" 
    }, 

用戶模式:

<?php 

namespace App; 
use Eloquent; 

use Illuminate\Auth\UserInterface; 
use Illuminate\Auth\Reminders\RemindableInterface; 

class User extends Eloquent implements UserInterface, RemindableInterface { 

目錄結構指向型號:

型號/應用/ user.php的

錯誤的嘗試'登錄'(這是在需要命名空間之前工作):

Symfony \ Component \ Debug \ Exception \ FatalErrorException 
Class '\User' not found 

登錄函數:

public function postSignin(){ 
    if (Auth::attempt(array('email'=>Input::get('email'), 'password'=>Input::get('password')))) { 

    $title = Auth::user()->title; 
    $surname = Auth::user()->surname; 

我已經編輯composer.json文件後,運行命令 '作曲家轉儲autload'。

任何幫助將非常感激,爲什麼這不再工作。

回答

3

如果你正在跟蹤psr-0那麼你的模型的目錄結構應該是:

app/ 
    models/ 
     App/ 
      User.php 

並嘗試設置在配置模型,請訪問:app/config/auth.php

變化模型

'model' => '\App\User'

祝你好運!

+0

謝謝,egig,它完美的工作。 – Ben

+0

即使使用psr-4記住在config/auth中設置模型也很有幫助。謝謝 – isimmons

相關問題