Welcome Guest, Not a member yet? Register   Sign In
extending the controller
#1

(This post was last modified: 03-16-2023, 10:46 PM by InsiteFX.)

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.
Reply
#2

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();
    }

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB