[英]Silex controller not found
I'm new user of Silex framework and I have a little (huge for me) problem with registering route to controller. 我是Silex框架的新用户,在注册到控制器的路由时遇到了一些小问题(对我来说很麻烦)。 My controller can not be found by Silex. Silex找不到我的控制器。 Here is my tree of files: 这是我的文件树:
My composer.json file: 我的composer.json文件:
{
"require": {
"silex/silex": "~1.3",
"twig/twig": "^1.24",
"doctrine/dbal": "~2.2"
},
"autoload": {
"psr-4": {
"Controller\\": "web/"
}
}
}
My index.php file in web directory: 我在Web目录中的index.php文件:
<?php
// web/index.php
require_once __DIR__.'/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Response;
use Silex\Provider\UrlGeneratorServiceProvider;
use Silex\Provider\ValidatorServiceProvider;
use Silex\Provider\ServiceControllerServiceProvider;
use Silex\Provider\HttpFragmentServiceProvider;
$app = new Silex\Application();
$app['debug']=TRUE;
$app->get('/','HomeController::index');
$app->run();
and HomeController.php file: 和HomeController.php文件:
<?php
/**
* Created by PhpStorm.
* User: Oskar
* Date: 2016-02-07
* Time: 02:27
*/
namespace web\Controller{
use Symfony\Component\HttpFoundation\Request;
use Silex\Application;
use Silex\ControllerCollection;
class HomeController
{
public function index()
{
return 'Hello Controller';
}
}
}
My error: 我的错误:
Regards. 问候。
Hi you should use below line i hope it will help you 嗨,您应该使用下面的文字,希望对您有所帮助
use Silex\Api\ControllerProviderInterface;
class HomeController implements ControllerProviderInterface {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.