Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter HMVC modules and javascript files

I've just started learning about HMVC in CodeIgniter.

So far I've been enjoying having modular controllers, but problems come when I wish to include javascript.

It seems to me that I'll have to include javascript file from the view instead of the widgets which isn't really good because I tend to forget which widgets has to come with which javascript file.

Anyone has a better way to do it?

like image 895
Jonathan Chow Avatar asked Jan 25 '26 21:01

Jonathan Chow


2 Answers

Assets (css,js,images) you should place outside of application folder so you can access them directly.

Thus , you load them using base_url() to start with, and base_url() remains same from wherever you call it.

if you want to split assets in modules as well, perhaps make an assets folder, which further contains folders with module names, each containing css,js,images files. then use base_url()."/assets/module_name/js/script.js" or something of the sort

like image 76
Ahmed-Anas Avatar answered Jan 27 '26 09:01

Ahmed-Anas


As default, you cannot access files within your module folder as it was protected by .htaccess in applications folder.

To allow access in your assets/public folder within your module folder just add another .htaccess within the folder and add the following line.

Allow From All

like image 41
Joesel Duazo Avatar answered Jan 27 '26 11:01

Joesel Duazo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!