添加命名空间后的错误。无法访问模型

时间:2013-12-08 20:43:08

标签: namespaces laravel-4

我必须将命名空间合并到我的项目中,因为我需要使用名为“Event”的模型,以避免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文件后运行了'composer dump-autload'命令。

任何帮助将非常感谢为什么这不再起作用。

1 个答案:

答案 0 :(得分:2)

如果您关注psr-0,那么您的模型的目录结构应为:

app/
    models/
        App/
            User.php

并尝试在配置中设置模型,转到:app/config/auth.php

更改模型

'model' => '\App\User'

祝你好运!