早上好,
在过去的几周里,我一直在使用 Silex 开发一个应用程序,昨晚我要么对我的代码进行了更改,要么在更新 composer 的过程中更新了一些东西,但它不起作用。
我正在使用 \\’Igorw\\\\\\\\ConfigServiceProvider\\’ 来加载链接到我配置的控制器的路由。但是当我访问网页时,我收到错误消息:
| 1 | InvalidArgumentException : Unable to find controller “controllers.admin:index” . |
我的文件如下
composer.json
| 1 2 3 4 5 6 7 8 9 10 11 12 13 |
{ “require” : { “silex/silex” : “1.2.*@dev” , “igorw/config-service-provider” : “1.2.*@dev” , “symfony/yaml” : “2.5.*@dev” } , “autoload” : { |
config/routes.yml
| 1 2 3 4 5 |
config .routes : admin : pattern : /admin defaults : { _controller : ‘controllers.admin:index’ } method : GET |
web/index.php
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php
require_once __DIR__ . ‘/../vendor/autoload.php’ ; use \\Igorw\\Silex\\ConfigServiceProvider ; $app = new Silex\\Application ; $app [ “debug” ] = true ; // load the routes // register the classes $app -> run ( ) ; |
src/turtle/controllers/AdminController.php
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php
namespace Turtle\\Controllers ; use Silex\\Application ; class AdminController { protected $app ; public function __construct (Application $app ) { public function index (Request $request ) { } |
我检查了 $app 变量,它包含一个实例化的 AdminController 类,但由于某种原因,系统正在正确地选择控制器。我真的不明白发生了什么,只能把它归结为一个模糊的错误或更新。
谁能解释一下这个问题?
谢谢,罗素
我在 Silex GitHub 问题网站 https://github.com/silexphp/Silex/issues/919 上交叉发布了此问题,问题已被指出。向戴夫·马歇尔致敬。
web/index.php 文件没有注册 Silex ServerControllerServiceProvider。在系统中添加它后,现在可以工作了。更新后的文件现在看起来像:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php
require_once __DIR__ . ‘/../vendor/autoload.php’ ; use \\Igorw\\Silex\\ConfigServiceProvider ; $app = new Silex\\Application ; $app [ “debug” ] = true ; $app -> register ( new Silex\\Provider\\ServiceControllerServiceProvider ( ) ) ; // load the routes // register the classes $app -> run ( ) ; |
我一定是在重新组织文件时无意中删除了该行。
- 同样的事情发生在我身上,添加注册行解决了它。

评论(0)