Welcome Guest, Not a member yet? Register   Sign In
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



Theme © iAndrew 2016 - Forum software by © MyBB