CodeIgniter Forums
CI3->CI4 conversion approach - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forum-31.html)
+--- Thread: CI3->CI4 conversion approach (/thread-66244.html)



CI3->CI4 conversion approach - twpmarketing - 09-26-2016

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.

Thanks


RE: CI3->CI4 conversion approach - kilishan - 09-26-2016

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)
Code:
<?php namespace App\BaseClasses;

class Controller extends \CodeIgniter\Controller
{
   public function __construct(...$params)
   {
       parent::__construct(...$params);

      // Do your stuff here...
   }
}

File: application/Controllers/UserController.php

Code:
<?php namespace App\Controllers;

class UserController extends \App\BaseClasses\Controller
{
   public function index()
   {
        echo view('users/index');
   }
}



RE: CI3->CI4 conversion approach - twpmarketing - 09-26-2016

Kilishan;
Thank you. It looks like the major difference is the use of namespaces. I can work with this.


RE: CI3->CI4 conversion approach - jlp - 09-26-2016

Definitely a work in progress, but might help too ... https://github.com/jim-parry/CodeIgniter4-website
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.


RE: CI3-&gt;CI4 conversion approach - twpmarketing - 09-26-2016

James, thank you.  That will take a little longer to digest...