If you didn't move the controllers
directory from the original location (which is ?project_root?/app/controllers/
, you must guarantee that:
Laravel's autoload has the controller
directory. Navigate to ?project_root?/app/start/global.php
. You need to have something like this:
(...)
ClassLoader::addDirectories(array(
app_path().'/commands',
app_path().'/controllers',
app_path().'/models',
app_path().'/database/seeds',
));
(...)
Take notice to this line app_path().'/controllers'
. It must exist.
Also, open your composer.json
file and verify that the following lines exist:
(...)
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
],
(...)
Make sure that you have the line with app/controllers
If you have this lines and you still get the same message, go to your project root and run the following command from the command-line composer dumpautoload -o
.
Laravel works with Composer, which is a dependency management tool for PHP. It also prepares an autoload file for all your project classes (see composer docs). When you run the composer dumpautoload
command, it will create some files within ?project_root?/vendor/composer
.
Make sure that you can find the class AdminCMSController
in the file ?project_root?/vendor/composer/autoload_classmap.php
. You should see something like this:
'AdminCMSController' => $baseDir . '/app/controllers/AdminCMSController.php',
If you have changed the default location of your controllers
directory, you have to do either one of the following steps. However, since you are not defining a namespace in your class, it doesnt seem likely that this is your problem:
Use PSR-0 for autoloading classes. Imagine that you have the following folder structure:
/app
/commands
/config
/database
/Acme
/controllers
You have to specify the Acme
folder in your composer.json
, like this:
"autoload": {
"classmap": [
"app/commands",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
],
"psr-0": {
"Acme": "app/"
}
},
After this you need to update you composer autoload files with the command composer dumpautoload
.
If you do not want to use the PSR-0 for autoloading, you need to change your routes file from this
Route::controller('cms','AdminCMSController');
to this:
Route::controller('cms','AcmecontrollersAdminCMSController');
IF you use PSR-0, you need to namespace your classes like this:
<?php namespace Acmecontrollers;
class AdminCMSController extends BaseController {
(...)
}
Curious about the Acme
reference? I was too. Refer to the wikipedia.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…