CodeIgniter Forums
Modules? Easy? Absolutely not! - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Modules? Easy? Absolutely not! (/showthread.php?tid=77446)

Modules? Easy? Absolutely not! - blaasvaer - 09-02-2020


I'm trying to wrap my head around using Modules in CI4 – I used to be fine with the (third party) HMVC version in CI3. But holy mother of c... am I confused. Setting autoloads, setting routes, fiddling with 'explorers'(?), seriously!?

Why hasn't it simply been implemented so that I can dump whatever module I've created into a folder called Modules (somewhere that makes sense) and start using them (yeah, yeah, performance yadda yadda)? Why do I have to go through hoops and loops to even understand the structure and all the things I have to fiddle with ... I've read the docs over and over and still end up googling the crap out of it ... and getting even more confused as the questions (and non working 'solutions') are all over the place ... so far CI 4 has not been a nice experience when is comes to ANYTHING besides the 'basics'.

Does ANYONE know of an isolated app that show HOW I can implement and use a simple module in an app? Now, THAT would be nice ... and probably even helpful.

Sorry if I sound frustrated, if, then that is actually the case. But sorry anyway.

RE: Modules? Easy? Absolutely not! - ajmeireles - 09-02-2020

I'm be able to help you. Provide me your Skype id, so we can talk about that.

RE: Modules? Easy? Absolutely not! - InsiteFX - 09-03-2020

Example Blog Module:

Root with ./app

-- Config
---- Routes.php
---- etc;
-- Controllers
-- Any other app folders you need.
-- Views


Add your namespace and module folder name.

PHP Code:
// Notice the \ back slash        Notice the forward slash
'Blaasvaer\Blog' => ROOTPATH 'Blaasvaer/Blog'// Module Blog,
// Namespace                       Folder path. 

In your Blog module under the Config/Routes.php ad this:

PHP Code:
 * Blaasvaer/Blog: routes file.

$routes->group('', ['namespace' => 'Blaasvaer\Blog\Controllers'], function($routes)

Create your Blog Controller and View file in you Blog Module and it should work.

RE: Modules? Easy? Absolutely not! - blaasvaer - 09-03-2020

Thanks, I'll give it a got ... but right now I'm struggling to get even composer to create a project. So, I guess I have to take the VERY long road around CI4.

RE: Modules? Easy? Absolutely not! - InsiteFX - 09-03-2020

Just copy the composer.phar file into the project root.

When running composer make sure your in the project root.