• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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');
   }
}
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#3
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.