• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to extend the Controller core class

#3
Showing code you tried and telling the actual error you received is the best way to get a good answer. That said - extending the Controller class is pretty simple - you're just extending a normal PHP class, no special MY_ prefixes needed or anything like that.

1. Make a new BaseController class/file. Make sure it is namespaced so the autoloader can find it.

PHP Code:
<?php namespace App\Controllers;

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


2. Have all of your new controllers extend BaseController instead of CodeIgniter\Controller.

Note: you don't need to have the constructor shown here unless you need additional tasks in the constructor. I just showed it here to remind people about the parameter packing/un-packing available in PHP 7.
Reply


Messages In This Thread
How to extend the Controller core class - by Edel - 07-22-2017, 03:35 PM
RE: How to extend the Controller core class - by kilishan - 07-22-2017, 07:46 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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