简体   繁体   English

在LARAVEL 4.1中为我的自定义模型使用NAMESPACE和USE的正确方法

[英]Proper way of using NAMESPACE and USE for my custom model in LARAVEL 4.1

My composer.json currently have these: 我的composer.json当前具有这些:

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

If I have 如果我有

<?php
namespace Models;
use Eloquent;
class User extends Eloquent {

I get this error: Class 'User' not found 我收到此错误: Class 'User' not found

But if I only have: 但是,如果我只有:

<?php
class User extends Eloquent {

I can call instantiate/call User class via new User() or User::* . 我可以通过new User()User::*调用实例化/调用User类。

I don't know why. 我不知道为什么 First time using namespace and use in PHP. 第一次使用namespace并在PHP中use I understand the use of namespace and use , it just, .... Is it the setup? 我了解namespace的使用并use ,它只是....是安装程序吗? Or there's more configuration? 还是有更多配置? Thanks! 谢谢!

Eloquent namespaces is 'Eloquent' => 'Illuminate\\Database\\Eloquent\\Model', . 雄辩的名称空间是'Eloquent' => 'Illuminate\\Database\\Eloquent\\Model',

You can app/config/app.php 'aliases' => array() examine. 您可以app / config / app.php'aliases 'aliases' => array()检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM