2

So, I'm making a CMS at the mo, and using the modular extensions HMVC CI 2.0. It's lovely. I'm wondering the correct method for keeping my assets (js, css, img) related to a module within the module directory.

The problem being, how do I link to these assets? Let's say I'm using a template engine and passing the js files to load for a specific page:

$js[] = 'assets/js/my_js.js';

I suppose I'm asking this all wrong, but is there an easy way to link using the current module's directory?

Thanks in advance.

Michael Watson
  • 454
  • 2
  • 6
  • 14

1 Answers1

0

There's nothing currently built in to CI or HMVC for this.

I prefer not to reference files that are allowed direct access, like images/js/css, from within the application directory. Mainly because:

  • I don't want anyone to know what the guts of my app look like. By referencing files from directly within a module, you expose your application's directory structure.

  • I would never do this if I weren't using HMVC

  • You must now allow direct access to (certain) directories within the application via .htaccess. For security reasons, I prefer to simply disallow the entire thing.

I understand the desire to be as modular as possible, but to me it's not worth this hassle. I prefer to keep a separate directory in a public folder called "modules" (duplicating my application/modules structure), that has nothing but "assets" (css, js, images...).

I'd offer some code but I have no clue how you are adding js/css to your views - it's probably much different than the way I do it. It would be easy enough to write a function to detect the current module, controller, or method and change the asset folder automatically, but this may interfere with other shared assets. I'd suggest writing an entirely separate function for loading assets from modules.

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • What you outlined is exactly what I currently do- mirroring the module directory structure in an assets file completely detached from anything CI. I just think it's a bit botched, and would be nicer if all module things were kept together. That said, I agree with you about people seeing 'the guts' of the operation. Maybe I'll keep it as I am / you are doing :) – Michael Watson Jun 09 '11 at 09:50
  • Another thing you could do is use some kind of cache system. You could `readfile()` the js/css from the module directory, combining files if you wish, and write a file to the public directory with the contents. The annoying part is you'd have to rewrite it on updates, either manually or triggered with `filemtime()` (cache file is older than a current file). – Wesley Murch Jun 09 '11 at 13:01