Reputation: 1972
How can we access a html file located inside Bundle folder.?
Refer attached screen
Upvotes: 0
Views: 378
Reputation: 2139
Controller Access
You can access to the root dir thanks to this :
$this->get('kernel')->getRootDir();
It will place into app/
directory and then you can navigate as you want
So in your case I think this will be work:
$fileToYourPath = $this->get('kernel')->getRootDir().'/../src/C2Educate/ToolsBundle/Stripe/c2/c2.html'
Service Access
You can access to the root dir by injecting container (dependency injection pattern)
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'
}
}
In your services.yml, define your new service:
myclass:
class: ...\MyClass
arguments: ["@service_container"]
Upvotes: 2