Welcome Guest, Not a member yet? Register   Sign In
Overriding core classes
#1

(This post was last modified: 10-17-2018, 09:08 AM by imabot.)

I tryed to override the core controller following this page :
https://www.codeigniter.com/userguide3/g...asses.html

I added a new class in /application/core/ 


PHP Code:
<?php
class MY_Controller extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        echo 'Hello !';
        die();
    }


I checked, line 374 of /system/core/CodeIgniter.php is called properly :


PHP Code:
require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'


But constructor is not called. What am I doing wrong ?
Reply
#2

What's the problem?
Reply
#3

(This post was last modified: 10-17-2018, 12:46 PM by imabot.)

(10-17-2018, 12:25 PM)dave friend Wrote: What's the problem?

Constructor was not called. 

But I solved the problem myself : I didn't extend my controllers with MY_controller, it was still CI_controller.
Reply
#4

(This post was last modified: 10-17-2018, 02:39 PM by dave friend.)

Huh... go figure. I've created MY_Controller classes on many occasions without any problem.

Line #374 from Codeigniter.php only makes the class code available, it does not instantiate it.

PHP Code:
require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'

The controller is instantiated on line #518

PHP Code:
$CI = new $class(); 

There's a whole bunch of error checking going on in between most of which results in a 404 if all the pieces cannot be found.

You don't mention getting any errors. Did you?
Reply
#5

(10-17-2018, 02:37 PM)dave friend Wrote: You don't mention getting any errors. Did you?

That's very kind to you to answer to me. I no longer have any problems or errors : everything is fine now as I explained previously:


Quote:I solved the problem myself : I didn't extend my controllers with MY_controller, it was still CI_controller.

That was my mistake.
Reply
#6

(This post was last modified: 10-18-2018, 02:49 AM by InsiteFX.)

Just a note here you do not have to name the class MY_Controller, you can name the class whatever you want.
It just needs to be saved with the MY_Controller.php filename.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(10-18-2018, 02:49 AM)InsiteFX Wrote: Just a note here you do not have to name the class MY_Controller, you can name the class whatever you want.
It just needs to be saved with the MY_Controller.php filename.

Thank you, very useful.
Reply
#8

(10-18-2018, 12:26 AM)imabot Wrote: That's very kind to you to answer to me. I no longer have any problems or errors : everything is fine now as I explained previously:
Quote:I solved the problem myself : I didn't extend my controllers with MY_controller, it was still CI_controller.
That was my mistake.

And my mistake was not understanding your explanation of the problem. Blush

I'm glad to hear it was a simple problem. Sometimes those kinds of "bugs" are the hardest to find.
Reply
#9

(10-18-2018, 05:30 AM)dave friend Wrote:
(10-18-2018, 12:26 AM)imabot Wrote: That's very kind to you to answer to me. I no longer have any problems or errors : everything is fine now as I explained previously:
Quote:I solved the problem myself : I didn't extend my controllers with MY_controller, it was still CI_controller.
That was my mistake.

And my mistake was not understanding your explanation of the problem.  Blush

I'm glad to hear it was a simple problem. Sometimes those kinds of "bugs" are the hardest to find.

Maybe you could help me with the next one : https://forum.codeigniter.com/thread-71960.html !
Reply




Theme © iAndrew 2016 - Forum software by © MyBB