Laravel 4 中未找到库类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15590316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Library Class not found in Laravel 4
提问by Nyxynyx
I am migrating a working production L3 site to use L4. When a controller calls a library class (app/libraries/adminthing.php
), I get the error Error: Class 'adminthing' not found in /var/www/l4/app/controllers/AdminController.php line 15
我正在迁移一个工作生产 L3 站点以使用 L4。当控制器调用库类 ( app/libraries/adminthing.php
) 时,出现错误Error: Class 'adminthing' not found in /var/www/l4/app/controllers/AdminController.php line 15
start/global.php
开始/global.php
ClassLoader::addDirectories(array(
app_path().'/controllers',
app_path().'/models',
app_path().'/database/seeds',
app_path().'/libraries',
));
I have also done composer dumpautoload
after adding the library class. What else did I miss out?
composer dumpautoload
添加库类后我也做了。我还错过了什么?
回答by stormpat
You can autoload folders from composer.json. If you have some custom classes in a folder under /app you can add the folder to composer.json, and after this the classes are auto loaded.
您可以从 composer.json 自动加载文件夹。如果您在 /app 下的文件夹中有一些自定义类,您可以将该文件夹添加到 composer.json,然后自动加载类。
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/customlib" <-- add this
]
},
Then composer dump-autoload, and you can use the classes!
然后composer dump-autoload,你就可以使用这些类了!