【发布时间】:2013-03-11 14:15:27
【问题描述】:
我正在开发一个新的 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 时。
END EDIT
我不知道这可能来自哪里 - 我已经在我的其他工作项目中搜索了这个函数定义,但在代码中找不到它。我想我可能缺少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]
}
}
}
“破碎”composer.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;
}
}
【问题讨论】:
-
您的问题中损坏的 composer.json 文件中包含的设置是这与工作文件之间的唯一区别吗?
-
你能告诉我们你的 FeedController 吗,例如,缩短了,所以你只包括一个路线?
-
@Adam-E 文件完全按照原样复制。
-
@Maerlyn 我添加了
FeedsController.php的代码 -
您在底部缺少
return $controller语句,这是这里的错误还是您的代码中的错误?