我的项目使用Laravel,我创建了一个服务提供商,它位于app/services/ToolboxServiceProvider.php
中,我添加了
'providers' => array(
....
'servicesToolboxServiceProvider',
);
在我的app.php配置文件中。现在,当加载应用程序时,它说服务提供商找不到,我知道我在该提供商阵列中的路径设置有问题,问题是:如何使其正确?提前谢谢。
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
您应该添加到composer.json
:的autoload
=>classmap
部分
"app/services",
所以它应该看起来像:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/services",
]
},
在您的提供商文件中,一开始您应该有:
<?php namespace services;
(小写)。
在这些更改之后,您应该运行:
composer dump-autoload
重建类映射
在app/services
文件夹中使用类似的东西创建服务提供商,注意namespace
:
<?php
namespace Services;
use IlluminateSupportServiceProvider;
class ToolboxServiceProvider extends ServiceProvider
{
//...
}
然后在providers
数组中添加'ServicesToolboxServiceProvider'
。然后在composer.json
文件的classmap
部分中添加"app/services"
,并转储自动加载器。
composer dump-autoload?
吗