【问题标题】:Errors after namespace addition. Unable to access models添加命名空间后的错误。无法访问模型
【发布时间】:2013-12-09 20:57:38
【问题描述】:

我必须将命名空间合并到我的项目中,因为我需要使用一个名为“事件”的模型,从而避免 Laravel 使用的预定义“事件”出现错误。

作曲家.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 {

指向模型的目录结构:

models/app/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”。

对于为什么这不再起作用的任何帮助,我们将不胜感激。

【问题讨论】:

    标签: namespaces laravel-4


    【解决方案1】:

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

    app/
        models/
            App/
                User.php
    

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

    更换型号

    'model' =&gt; '\App\User'

    祝你好运!

    【讨论】:

    • 即使 psr-4 记得在 config/auth 中设置模型也很有帮助。谢谢
    猜你喜欢
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    相关资源
    最近更新 更多