CodeIgniter Forums
extending the controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18)
+--- Thread: extending the controller (/showthread.php?tid=87134)



extending the controller - VateUthnerdal - 03-16-2023

I am attempting to follow CodeIgniter tutorials that focus on extending the controller. The tutorial advises placing the following code in the MY_Controller file:

PHP Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class 
MY_Controller extends Controller
{
    function __construct()
    {
        parent::__construct();
    }



However, this results in the following error:
Fatal error: Class 'Controller' not found in /home/chimeri1/public_html/application/libraries/MY_Controller.php on line 3
If I substitute CI_Controller instead of Controller, the code works. What is the difference between the two?
Also, should the closing PHP tag ?> be included at the end of the MY_Controller file? Some tutorials omit it.
Thank you in advance for your assistance.


RE: extending the controller - InsiteFX - 03-16-2023

It's CI_Controller not Controller for CodeIgniter 3.
CodeIgniter 4 uses Controller.

PHP Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class 
MY_Controller extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }