我的助手類的代碼如下:如何獲得在助手類的根路徑 - Symfony2的
public function getPlaceholders()
{
try {
echo $this->getParameter('kernel.root_dir');
} catch (ParseException $e) {
printf("Unable to parse the YAML string: %s", $e->getMessage());
}
return $this->placeholders;
}
它返回如下錯誤:
Attempted to call an undefined method named "getParameter" of class "AppBundle\Helper\Placeholders".
請諮詢我就可以了。
不存在於'Placeholders'類'getParameter'方法錯誤的手段。 – Federkun
那麼如何在我的助手類中使用getParameter? @Federkun –
'getParameter'是一個容器的方法,只需在'Placeholder'中注入並使用它。 (http://stackoverflow.com/questions/17126277/how-to-give-container-as-argument-to-services) – Federkun