問題是,爲什麼Symfony2的組件,類實例
$config = array(__DIR__ . '/app/config');
$locator = new Symfony\Component\Config\FileLocator($config);
$loader = new Symfony\Component\Routing\Loader\YamlFileLoader($locator);
$routes_collection = $loader->load('routes.yml');
這裏$ routes_collection是的Symfony \分量\路由\ RouteCollection一個實例,該代碼工作正常。
這裏
# config.yml
file_locator:
class: Symfony\Component\Config\FileLocator
arguments: ['%app_root%/app/config']
route_collection:
class: Symfony\Component\Routing\Loader\YamlFileLoader
arguments: ["@file_locator"]
calls:
- [load, ['routes.yml']]
#app.php
$routes_collection = $container->get('route_collection')
$ routes_collection是的Symfony \分量\路由\裝載機\實例YamlFileLoader,如果我用它來與的Symfony \分量\路由\匹配器\ UrlMatcher上午越來越:
Argument 1 passed to Symfony\Component\Routing\Matcher\UrlMatcher::__construct() must be an instance of Symfony\Component\Routing\RouteCollection, instance of Symfony\Component\Routing\Loader\YamlFileLoader given.
更新
@Paziツ,但如何,如果我想使用route_collection在匹配
matcher:
class: Symfony\Component\Routing\Matcher\UrlMatcher
arguments: ["@route_collection", "@context"]
感謝你爲這個,我更新了一點問題,問題是我想用「匹配器」服務使用所有這些,也許你有想法如何通過配置解決這個問題? – MyMomSaysIamSpecial
通過php而不是yaml進行配置嗎? –
呵呵,得出了同樣的結論,並在20分鐘前完成了對php的遷移:)感謝您的幫助! – MyMomSaysIamSpecial