Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Assets in modules vs. public (best practices)
  • Hi,
    I'm wondering what is recommended in Fuel when it comes to module-based assets such as CSS, JS and imags. By default, these are placed in public/assets. However, I would like to organize all of these assets by module.

    So for example, for CSS, it seems my placement options are:
    1. public/assets/css  (default)
    2. public/assets/<module>/css
    3. public/assets/css/module
    4. fuel/app/modules/<module>/assets/css
    5. fuel/app/modules/<module>/views/assets/css
    I like the idea of organizing modules as plugins. Personally I prefect option #4. However, I don't want to "break" fuel architecture.  What do you recommend?
  • Currently that is not possible, since assets need to be publicly accessable (hence they have to be in ./public), while your module code shouldn't be.

    The only way to deal with 4 and 5 is to make a controller that serves the asset. You could create a rewrite rule that would rewrite

    fuel/app/modules/<module>/assets/css/somefile.css

    to

    /asset/fetch/fuel/app/modules/<module>/assets/css.somefile.css

    and create a controller called Controller_Asset, with a method action_fetch(), that will load and return the file requested.

    If you go this route, make sure to do proper validation, to make sure nobody requests your servers password file! Use the File class, and define app/modules are the Area, so no requests can be done outside it.
  • Makes perfect sense. So would you recommend #2 or #3 as teh best architecture? Is it impotant to maintain the assets/css construct as far as forward compatibility or would it be harmless to go to assets/<module> ?

  • I don't think there is such a thing as "best".

    We're looking into solving this issue for Fuel v2, and also build this into the Theme class (so themes will have asset and module support too).
  • So based on the Fuel v2 layout, which of these would best port over?

  • Can't tell you, because we haven't decided on a new solution for Assets, and we haven't started on the Theme class yet. We haven't even decided whether or not we're going to support this outside themes.

    But if you want my 2 cents (without any promise), I'd say option 4. Assets definitely don't go into views, so 5 is out of the question.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion