Welcome Guest, Not a member yet? Register   Sign In
CI3->CI4 conversion approach
#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


Messages In This Thread
CI3->CI4 conversion approach - by twpmarketing - 09-26-2016, 09:28 AM
RE: CI3->CI4 conversion approach - by kilishan - 09-26-2016, 11:38 AM
RE: CI3->CI4 conversion approach - by jlp - 09-26-2016, 12:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB