Reputation: 915
Ok I'm using Laravel 4.1... I'm trying to get my nested controllers to load.. It runs fine on my local when I was doing my previous method of just running a composer dump-autoload, but on a shared hosting provider, I can't run that command line...
Anyway, here is how my composer.json file looks:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"laravelbook/ardent": "2.4.*",
"loic-sharma/profiler": "1.1.*",
"intervention/image": "dev-master",
"mews/purifier": "dev-master"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/controllers/dash",
"app/controllers/dash/product",
"app/models",
"app/models/Product",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
],
"psr-0": {
"App\\Controllers": "app/controllers",
"App\\Controllers\\Dash": "app/controllers/dash",
"App\\Controllers\\Dash\\Product": "app/controllers/dash/product",
"App\\Models": "app/models",
"App\\Models\\Product": "app/models/Product"
}
},
"scripts": {
"post-install-cmd": [
"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": "dev"
}
Then here is a nested controller (Controllers/dash/MediaController.php)
<?php
namespace App\Controllers\Dash;
class MediaController extends BaseController { }
Then in my routes, I have:
Route::group(array('prefix' => 'dash', 'before' => 'auth'), function()
{
Route::controller('media', 'App\Controllers\Dash\MediaController');
});
But it's still giving me this error:
Class 'App\Controllers\Dash\MediaController' not found
Upvotes: 0
Views: 4026
Reputation: 87789
Unless you are using PSR-4 (or even PSR-0), you must execute
composer dump-autoload
Everytime you create new classes in your folders. So composer add those classes to the vendor/composer/autoload_classmap.php
file.
Looking at you PSR-0 autoloading structure, we can see that your controllers are set to:
"App\\Controllers": "app/controllers",
So now composer autoloading system will try to find your App\Controllers\Dash\MediaController
class in (something like) this folder:
/var/www/webapp/app/controllers/App/Controllers/Dash/MediaController.php
This is tough, I know, but PSR-4 is easier to understand, since
"App\\Controllers\\": "app/controllers",
Means that your controller file will be found at:
/var/www/webapp/app/controllers/Dash/MediaController.php
Upvotes: 2