I have a css file called 'style.css' and I want to load its content inside a controller. I didn't find any relevant solution when reading the official documentation (Cookbook included).
I think you would first need to get the path to the CSS directory, using something like:
$path = $this->get('kernel')->getRootDir() . '/../css' . '/path/to/file.css';
Then, load the CSS file into a string:
$css = file_get_contents($path);
Hope that helps!
Symfony2 provides a component called "Finder", check the doc
I found a simple solution if you have the path to the file then
$file = new SplFileInfo('/path/to/file.css', '', '');
and the method getContents
does the magic
$file->getContents();
But you will have to include the class
use Symfony\Component\Finder\SplFileInfo;
is also part of the finder library, but you don't need to search for the file you want to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With