gpt4 book ai didi

php - 在 Controller 中找不到接口(interface) 'Silex\ControllerProviderInterface'

转载 作者:可可西里 更新时间:2023-11-01 00:29:51 24 4
gpt4 key购买 nike

执行api.php时:

Fatal error: Interface 'Silex\ControllerProviderInterface' not found in C:\xampp\htdocs\lab\src\Api\UserController.php on line 9

Composer :

{
"require": {
"silex/silex": "^2.0"
},
"autoload": {
"psr-4": {
"Api\\": "src/Api"
}
}
}

api.php :

<?php
require_once __DIR__.'/vendor/autoload.php';
$app = new Silex\Application();

$app['debug'] = true;

$app->mount('/', new Api\UserController());

$app->run();

src/Api/UserController.php :

<?php
namespace Api;

use Symfony\Component\HttpFoundation\Request;
use Silex\Application;
use Silex\ControllerProviderInterface;

class UserController implements ControllerProviderInterface {

public function connect(Application $app) {
$factory=$app['controllers_factory'];
$factory->get('/','Api\UserController::home');
return $factory;
}

public function home() {
return 'Hello world';
}

}

文件的组织方式:

root folder
- composer.json
- api.php
- src
- Api
- UserController.php
- vendor (with silex files)

Silex 由 composer 安装 composer require silex/silex * at root folder.

最佳答案

Silex 2.0 引入了一些 BC 中断。其中之一是创建 Silex\Api namespace where the ControllerProviderInterface resides now .

所以你必须重构你的用户 Controller :

<?php
namespace Api;

use Symfony\Component\HttpFoundation\Request;
use Silex\Application;
use Silex\Api\ControllerProviderInterface;
// ^^^^^

class UserController implements ControllerProviderInterface {
// ...

关于php - 在 Controller 中找不到接口(interface) 'Silex\ControllerProviderInterface',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39059782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com