Welcome Guest, Not a member yet? Register   Sign In
CI3->CI4 conversion approach
#1

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
Reply
#2

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');
   }
}
Reply
#3

(This post was last modified: 09-26-2016, 05:27 PM by twpmarketing. Edit Reason: spelling )

Kilishan;
Thank you. It looks like the major difference is the use of namespaces. I can work with this.
CI 3.1 Kubuntu 19.04 Apache 5.x&nbsp; Mysql 5.x PHP 5.x PHP 7.x
Remember: Obfuscation is a bad thing.
Clarity is desirable over Brevity every time.
Reply
#4

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.
James Parry
Project Lead
Reply
#5

James, thank you.  That will take a little longer to digest...
CI 3.1 Kubuntu 19.04 Apache 5.x&nbsp; Mysql 5.x PHP 5.x PHP 7.x
Remember: Obfuscation is a bad thing.
Clarity is desirable over Brevity every time.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB