首页 > sylius ResourceController定义构造函数

sylius ResourceController定义构造函数

最经看sylius,在ResourceBundle的ResourceController中自定义了一个构造函数。

public function __construct(Configuration $config)
{
$this->config = $config;
}

在symfony2的Controller中是不能自定义构造函数的。不知道他是如何实现的


将controller作为一个service,路由表中使用sylius.controller.cart:indexAction这样的形式,这样就可以在发送请求的同时,将service初始化。至于构造函数中的参数,就依你的service.xml的argument属性而定。依赖注入的方式比较灵活,可以配置xml或者yml,也可以在DependencyInjection文件中配置

【热门文章】
【热门文章】