Thomas Kelly's answer is good (and it works!), But if you use dependency injection and / or don't want to bind your code directly to the kernel, you'd better use the FileLocator class / service:
$fileLocator = $container->get('file_locator'); $path = $fileLocator->locate('@MyBundle/path/to/file.txt')
$fileLocator will be an instance of \Symfony\Component\HttpKernel\Config\FileLocator . $path will be the full, absolute path to the file.
Even if the file_locator service file_locator uses the kernel, it is a much lesser dependency (itβs easier to replace your own implementation, use test twins, etc.).
To use it when injecting dependencies:
fazy Jul 09 '14 at 14:28 2014-07-09 14:28
source share