我的助手类的代码如下:如何获得在助手类的根路径 - 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