开发者

Where to put core resources in Symfony2?

I started to build a website with Symfony2, and I had a little bit of a quandary about resources.

The Symfony2 Book says that every resource file have to be in a Bundle, but what about the most essential images, .js and .css files that I use in the base.html.twig file on every page?

Should I make a CoreBundle or something similiar, just for these files, or should I put these in the app\Resources folder (or directly in the web folder, maybe)? If I can 开发者_运维技巧use the app\Resources folder for these, how can I reference these files from the template?

Making a Bundle just for this seems a little unnecesary, and the asset urls for these files are ugly too (e.g. '/bundles/projectcore/images/logo.jpg') in my opinion.

What's the best practice here?


I've had situations where I've kept all files in /web (i.e. /web/js) and others where I've kept them within an 'Assets' bundle.

If you're developing a bundle that's going to be reused in numerous projects, it makes sense to store the assets in that bundle. I think you would then publish/install those assets to the web folder using the command line. For example, let's say you had a BlogBundle that required specific css. You would store the css in that bundle, so the next time you use BlogBundle for a project you could easily reuse the css.

As with many other things with Symfony2, your personal preference plays a big part in these decisions. I recommend staying consistent though with where you store your assets. Having to manage assets split in three different locations (web, AssetsBundle, other bundles) could be a big headache. So pick a location, and try to stay consistent.

As for accessing assets from app/Resources... you may be able to use Assetic for this. I'm not very familiar with it, but I believe you can load assets from anywhere within your project. I'd actually recommend taking a look at the core Assetic code (look in vendor\Assetic) instead of the Symfony2 Assetic helper because you'll get a better idea of just what's possible.


We used a symlink in Linux so that /web/bundles/projectcore/images points to src/Bundle/Resources/public/images

With Subversion in Netbeans, it does work. The nice thing is that all your application remains in the /src/Bundle folder

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜