最經(jīng)看sylius,在ResourceBundle的ResourceController中自訂了建構(gòu)子。
#
public function __construct(Configuration $config)
{
$this->config = $config;
}
在symfony2的Controller中是不能自訂建構(gòu)子的。不知道他是如何實(shí)現(xiàn)的
業(yè)精于勤,荒于嬉;行成于思,毀于隨。
將controller作為一個(gè)service,路由表中使用sylius.controller.cart:indexAction這樣的形式,這樣就可以在發(fā)送請(qǐng)求的同時(shí),將service初始化。至於建構(gòu)子中的參數(shù),就依照你的service.xml的argument屬性而定。依賴注入的方式比較靈活,可以配置xml或yml,也可以在DependencyInjection檔案中配置