Where to host core resources in Symfony2?

I started building a website with Symfony2, and I had a bit of a resource constraint.

The Symfony2 book says that every resource file should be in the Bundle, but what about the most important .js and .css files that I use in the base.html.twig file on every page?

Should I make CoreBundle or something similar, only for these files, or should I put them in the app \ Resources folder (or directly in the web folder, maybe)? If I can use the app \ Resources folder for them, how can I link to these files from the template?

Creating a bundle just for this seems a little unnecessary, and the asset url for these files is also ugly (like "/bundles/projectcore/images/logo.jpg"), in my opinion.

What is the best practice here?

+8
php symfony
source share
2 answers

I had situations when I saved all the files in / web (for example, / web / js) and others, where I saved them in the "Assets" bundle.

If you are developing a package that will be reused in many projects, it makes sense to store assets in this package. I think you will then publish / install these assets to a web folder using the command line. For example, suppose you have a BlogBundle that requires a specific css. You would save css in this package, so the next time you use BlogBundle for a project, you can easily reuse css.

As with many other things with Symfony2, your personal preferences play a big role in these decisions. I recommend staying constant, but with where you store your assets. The need to manage assets shared in three different places (network, AssetsBundle, other packages) can be a big headache. So choose a location and try to stay consistent.

As for accessing assets from the app / resources ... you can use Assetic for this. I am not very familiar with this, but I believe that you can upload assets from anywhere in your project. I would recommend taking a look at the main Assetic code (see vendor\Assetic ) instead of the Symfony2 Assetic helper, because you get a better idea of ​​what is possible.

+6
source share

We used a symbolic link on Linux so that / web / bundles / projectcore / images points to src / Bundle / Resources / public / images

It works with Subversion in Netbeans. It's nice that your entire application remains in the / src / Bundle folder

+2
source share

All Articles