Reputation: 647
How can I access "web" folder from config.yml in a symfony2 app ? I have tried %web%, %base_dir%, %asset_dir% and am running into a brick wall.
Upvotes: 4
Views: 5566
Reputation:
In Symfony 3.3, we're introducing a lot of changes and simplifications to prepare us for the fascinating Symfony 4.0 release that will take place on November 2017.
Some of those changes are technically minor but will have a profound effect in your applications. In Symfony applications, the well-known getRootDir() method of the Kernel class and its counterpart kernel.root_dir parameter are misleading.
They return the path where the application kernel (usually AppKernel.php) is stored. In Symfony 2 and 3 this is usually the app/ directory, so it's common to use expressions like %kernel.root_dir%/../var/ or %kernel.root_dir%/../web/. In Symfony 4, the kernel class has been moved to the src/ directory, so the previous expressions won't break.
However, given that most of the times getRootDir() is used to get the project root directory, in Symfony 3.3 we've decided to add a new method to the Kernel class called getProjectDir() which will give you exactly that.
This new method finds the project root directory by looking for the first directory that contains a composer.json file starting from the directory where the kernel is stored and going up until composer.json is found.
In practice, this means that your application can simplify most or all the expressions that use %kernel.root_dir%. For example: use %kernel.project_dir%/web/ instead of %kernel.root_dir%/../web/.
From : New in Symfony 3.3: A simpler way to get the project root directory
Upvotes: 0
Reputation: 1372
In config.yml
you can use %kernel.root_dir%/../web
.
If you want a handy shortcut, in your parameters.ini
you can define something like :
web_dir = %kernel.root_dir%/../web
Then in config.yml
you will use %web_dir%
.
Upvotes: 13
Reputation: 15082
You can access resources in your web directory using twig's asset() function.
<script src="{{ asset('bundles/yourbundle/js/jquery-1.7.2.min.js') }}" type="text/javascript"></script>
See http://symfony.com/doc/current/book/templating.html#linking-to-assets for more details.
I think you'll want to avoid setting local paths in your config/parameters file, try and keep everything as dynamic as possible.
Upvotes: 1