2016-08-03 36 views

回答

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"]