答案 0 :(得分:2)
控制器访问
由于这个原因,您可以访问根目录:
$this->get('kernel')->getRootDir();
它将放入app/
目录,然后您可以根据需要导航
所以在你的情况下,我认为这将是有效的:
$fileToYourPath = $this->get('kernel')->getRootDir().'/../src/C2Educate/ToolsBundle/Stripe/c2/c2.html'
服务访问
您可以通过注入容器(依赖注入模式)
来访问根目录use Symfony\Component\DependencyInjection\ContainerInterface;
class MyClass
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function doWhatever()
{
$root = $this->container->get('kernel')->getRootDir();
$fileToYourPath = $root.'/../src/C2Educate/ToolsBundle/Stripe/c2/c2.html'
}
}
在您的services.yml中,定义您的新服务:
myclass:
class: ...\MyClass
arguments: ["@service_container"]