我有這樣的錯誤在我的web應用程序:級「SocialWall /控制器/ HomeController的」不存在
InvalidArgumentException in ControllerResolver.php line 160: Class "SocialWall/Controller/HomeController" does not exist.
in ControllerResolver.php line 160
at ControllerResolver->createController('SocialWall/Controller/HomeController::indexAction') in ControllerResolver.php line 76
at ControllerResolver->getController(object(Request)) in HttpKernel.php line 136
at HttpKernel->handleRaw(object(Request), '1') in HttpKernel.php line 68
at HttpKernel->handle(object(Request), '1', true) in Application.php line 496
at Application->handle(object(Request)) in Application.php line 477
at Application->run() in index.php line 16
我用的Silex〜2.0,我剛纔重構我的控制器列表這樣的:
我的樹:
- 根/應用/ app.php
- 根/應用/ routes.php文件
- 袋鼠噸/ SRC /控制器/ HomeController.php
- 根/網絡/ index.php的
的index.php:
<?php
/** Front controller */
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
require __DIR__.'/../app/config/dev.php';
require __DIR__.'/../app/app.php';
require __DIR__.'/../app/routes.php';
$app->run();
routes.php文件
<?php
// Home page
$app->get('/', "SocialWall/Controller/HomeController::indexAction")->bind('home');
// Detailed info about an article
$app->match('/article/{id}', "SocialWall/Controller/HomeController::articleAction")->bind('article');
// Login form
$app->get('/login', "SocialWall/Controller/HomeController::loginAction")->bind('login');
//...
HomeController.php
<?php
namespace SocialWall\Controller;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use SocialWall\Domain\Comment;
use SocialWall\Form\Type\CommentType;
class HomeController {
/**
* Home page controller.
*
* @param Application $app Silex application
*/
public function indexAction(Application $app) {
$articles = $app['dao.article']->findAll();
return $app['twig']->render('index.html.twig', array('articles' => $articles));
}
//...
我的composer.json:
{
"require": {
"silex/silex": "2.0.*",
"doctrine/dbal": "2.5.*",
"twig/twig": "1.24.*",
"symfony/twig-bridge": "^3.1",
"symfony/security": "^3.1",
"symfony/form": "^3.1",
"symfony/config": "^3.1",
"symfony/translation": "^3.1",
"twig/extensions": "^1.3",
"symfony/validator": "^3.1",
"sorien/silex-pimple-dumper": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.5",
"symfony/css-selector": "^3.1",
"symfony/browser-kit": "^3.1",
"monolog/monolog": "^1.21"
},
"autoload": {
"psr-4": {"SocialWall\\": "src"}
}
}
怎麼了?
[編輯] 好的我修復它..在route.php函數的第二個參數我已經用'\'替換所有的'/'。 Initialy phpStorm強調我所有的 '\' 爲紅色,所以我代替 '\' 由 '/' ..謝謝phpStorm ...
你可以發佈你的composer.json文件嗎? – Matteo