CodeIgniter Forums

Full Version: CI3->CI4 conversion approach
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been considering how to convert my CI 3 designs to CI 4.

In CI 3, I use a "base controller" approach (thank you Jamie Rumbelow), which works very well, however, reading the unfinished docs for CI 4, I'm not seeing much which would support this.

Yes, I see that we can now create other extend-able objects such as models and controllers.

What I'd like to see explained is the current paradigm on making and using extensions to MVC objects.  Specifically controllers, but I'm open to model and general library extension.

The thing to remember is that it's all simple PHP - just classes.

The next thing I'd like to point out is that you don't have to use CI's Controller class - it just provides the current Request, Response, and Logger objects, with a couple of helper methods involved. You can use any class that you want as a controller and it should work just fine, I believe.

Assuming you do want to use the current Controller class, you would just create a new class that extends \CodeIgniter\Controller and use that as one of your BaseController's. Then, your controllers would extend that new class. So, something like:

File: application/BaseClasses/Controller.php (or wherever you want to store it)
<?php namespace App\BaseClasses;

class Controller extends \CodeIgniter\Controller
   public function __construct(...$params)

      // Do your stuff here...

File: application/Controllers/UserController.php

<?php namespace App\Controllers;

class UserController extends \App\BaseClasses\Controller
   public function index()
        echo view('users/index');
Thank you. It looks like the major difference is the use of namespaces. I can work with this.
Definitely a work in progress, but might help too ...
That is my rewrite of the CI website. As I find pieces that I need that have not been ported/rewritten, I tackle them - currently working on the Parser.
James, thank you.  That will take a little longer to digest...