我正在开发一个新的 Silex 项目,并且无法安装到我的控制器提供程序的路由。我之前在另一个项目中成功地做到了这一点,但是现在当我将以下路线放入时app.php
:
$app->mount('/', new CommonController());
$app->mount('/feeds', new FeedsController());
$app->mount('/admin', new AdminController());
我收到一个致命错误:Fatal error: Call to undefined method Silex\Route::setPath() in [root]/vendor/symfony/routing/Symfony/Component/Routing/RouteCollection.php on line 255
编辑:
安装根路由时不会引发错误。只有当我添加/feeds
或/admin
。
结束编辑
我不知道这可能来自哪里 - 我已经在我的其他工作项目中搜索了这个函数定义,但在代码中找不到它。我想我可能缺少一个库,composer.json
但我不确定它可能是哪一个 - 两个项目的文件几乎相同:
工作作曲家.json:
{
"name" : "lyrixx/Silex-Kitchen-Edition",
"type" : "library",
"description" : "A Silex Edition. This project is a base for your silex applications.",
"keywords" : ["framework"],
"homepage" : "http://lyrixx.github.com/Silex-Kitchen-Edition/",
"license" : "MIT",
"authors" : [
{
"name" : "Grégoire Pineau",
"email" : "lyrixx@lyrixx.info"
}
],
"repositories": [
{
"type": "package",
"package": {
"name" : "twitter/bootstrap",
"version" : "2.0.4",
"source" : {
"url" : "https://github.com/twitter/bootstrap.git",
"type" : "git",
"reference" : "v2.0.4"
}
}
}
],
"require": {
"php" : ">=5.3.3",
"silex/silex" : "dev-master",
"twig/twig" : "1.*",
"monolog/monolog" : "1.0.*",
"symfony/form" : "2.1.*",
"symfony/translation" : "2.1.*",
"symfony/twig-bridge" : "2.1.*",
"symfony/validator" : "2.1.*",
"symfony/yaml" : "2.1.*",
"symfony/config" : "2.1.*",
"kriswallsmith/assetic" : "1.0.*",
"twitter/bootstrap" : "2.0.4",
"doctrine/dbal" : "2.2.*",
"symfony/security" : "2.1.*",
"fate/silex-extensions" : "dev-master",
"michelf/php-markdown" : "1.3.*@dev",
"swiftmailer/swiftmailer" : ">=4.1.2,<4.2-dev"
},
"require-dev": {
"symfony/dom-crawler" : "2.1.*",
"symfony/css-selector" : "2.1.*",
"symfony/browser-kit" : "2.1.*"
},
"minimum-stability" : "dev",
"scripts": {
"post-install-cmd": "Lx\\Composer\\Script::postInstall"
},
"autoload": {
"psr-0": {
[autoload routes defined here]
}
}
}
“破碎”作曲家.json:
{
"require": {
"php" : ">=5.3.3",
"silex/silex" : "dev-master",
"twig/twig" : "1.*",
"monolog/monolog" : "1.0.*",
"symfony/form" : "2.1.*",
"symfony/translation" : "2.1.*",
"symfony/twig-bridge" : "2.1.*",
"symfony/validator" : "2.1.*",
"symfony/yaml" : "2.1.*",
"symfony/config" : "2.1.*",
"kriswallsmith/assetic" : "1.0.*",
"twitter/bootstrap" : "2.0.*",
"doctrine/dbal" : "2.2.*",
"fate/silex-extensions" : "dev-master",
"swiftmailer/swiftmailer" : ">=4.1.2,<4.2-dev"
},
"autoload": {
"psr-0": {
[autoload routes defined here]
}
}
}
同样,这甚至可能不是我问题的根本原因,只是我的直觉。谁能破译这里发生了什么?
第二次编辑:FeedsController.php
<?php
namespace Controllers;
use Controllers\CommonController;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
class FeedsController extends CommonController
{
public function connect(Application $app)
{
$controller = $app['controllers_factory'];
$controller->get('/', function (Request $request, Application $app)
{
return 'Yay!';
});
return $controller;
}
}