Welcome Guest, Not a member yet? Register   Sign In
Introduction to CodeIgniter 4 Blog Posts

(03-16-2016, 12:35 AM)sv3tli0 Wrote: Good thread.
Perhaps you have to add and info about the Module configurations how they will merge with the main app. 
Routes are always a difficult thing to handle in app <> modules relation.

I can't remember if it's mentioned in the articles or not, yet, but config files are simple classes. There's no more need a specialized config loader, so there's nothing special needed to load the config files in the rest of the app, just a simple $moduleConfig = new \Standard\Blog\Config\BlogConfig().

Routes must be handled manually. If you remember from the Routes article, routes can be mapped to namespaced classes, so a route might look like:

// Define a single route
$routes->add('blog', 'Standard\Blog\Controllers\BlogController::index');

// Map to the standard crud methods
$routes->resource('blog', ['namespace' => 'Standard\Blog\Controllers', 'websafe' => 1]);

// Or define routes within a group to minimize typing.
$routes->group('blog', function ($routes) {
   $routes->get('/', 'Blog::index');
   $routes->get('/(:id)', 'Blog::show/$1');
   $routes->post('/(:id)', 'Blog::update/$1');
}, ['namespace' => 'Standard\Blog\Controllers']);

The system won't scan through to find the routes files automatically, but you can create a routes file in your "module" and then load it manually in the main routes file. There's a section at the bottom of it that loads in the environment-specific routes file. You can load the file down there with standard includes.

Messages In This Thread
RE: Introduction to CodeIgniter 4 Blog Posts - by kilishan - 03-16-2016, 06:47 AM

Theme © iAndrew 2016 - Forum software by © MyBB