CodeIgniter Forums
MY_Controller technique not working with Reactor - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: MY_Controller technique not working with Reactor (/showthread.php?tid=38787)

Pages: 1 2 3


MY_Controller technique not working with Reactor - El Forum - 02-20-2011

[eluser]Wayne Smallman[/eluser]
[quote author="InsiteFX" date="1298181588"]Any Class that is in th systen/core directory that is extened has to be placed into the application/core directory. These are Core Classes.

MY_Controller is extending the system/core/CI_Controller, as you can see this is a Core Class.

Any Class that is extended that is in the system/libraries directory has to be placed into the application/libraries directory. These are Library Classes.[/quote]So would I be right in assuming the previous versions of CodeIgniter, prior to 2.0.x were quite relaxed in their handling of this hierarchy?

As I said, I'm working in a 1.7.x version and I have the MY_Controller in the application/libraries folder and it's working just fine.


MY_Controller technique not working with Reactor - El Forum - 02-20-2011

[eluser]moodh[/eluser]
[quote author="Wayne Smallman" date="1298243453"][quote author="InsiteFX" date="1298181588"]Any Class that is in th systen/core directory that is extened has to be placed into the application/core directory. These are Core Classes.

MY_Controller is extending the system/core/CI_Controller, as you can see this is a Core Class.

Any Class that is extended that is in the system/libraries directory has to be placed into the application/libraries directory. These are Library Classes.[/quote]So would I be right in assuming the previous versions of CodeIgniter, prior to 2.0.x were quite relaxed in their handling of this hierarchy?

As I said, I'm working in a 1.7.x version and I have the MY_Controller in the application/libraries folder and it's working just fine.[/quote]

The Core separation didn't exist prior to 2.0


MY_Controller technique not working with Reactor - El Forum - 02-20-2011

[eluser]Wayne Smallman[/eluser]
[quote author="narcisha" date="1298244433"][quote author="Wayne Smallman" date="1298243453"][quote author="InsiteFX" date="1298181588"]Any Class that is in th systen/core directory that is extened has to be placed into the application/core directory. These are Core Classes.

MY_Controller is extending the system/core/CI_Controller, as you can see this is a Core Class.

Any Class that is extended that is in the system/libraries directory has to be placed into the application/libraries directory. These are Library Classes.[/quote]So would I be right in assuming the previous versions of CodeIgniter, prior to 2.0.x were quite relaxed in their handling of this hierarchy?

As I said, I'm working in a 1.7.x version and I have the MY_Controller in the application/libraries folder and it's working just fine.[/quote]

The Core separation didn't exist prior to 2.0[/quote]Fair enough.


MY_Controller technique not working with Reactor - El Forum - 02-21-2011

[eluser]Dom Smith[/eluser]
Hi guys,

I was having the same problem when trying to extend the extended MY_Controller class. I followed InsiteFX's advice by putting all 3 files in the application/core folder but for some reason still can't get it to work.

My 3 files are named MY_Controller.php, Admin_Controller.php and Public_Controller.php and are all in application/core.

I've taken any code out of them and used the code above.

I then have a basic controller in application/controllers and when I extend Public_Controller it servers nothing, not even an error, but when I extend MY_Controller I get the correct output.

Anyone know what might be happening here? Any advice will be much appreciated. Cheers.


MY_Controller technique not working with Reactor - El Forum - 02-21-2011

[eluser]LuckyFella73[/eluser]
Please post your basic controller, maybe it's just a typo.
Without seeing any code its hard to tell.


MY_Controller technique not working with Reactor - El Forum - 02-21-2011

[eluser]Dom Smith[/eluser]
Code:
// application/core/MY_Controller.php
class MY_Controller extends CI_Controller {
    /**
     * Class Constructor
     *
     * @access    public
     * @return    void
     */
    public function __construct()
    {
        parent::__construct();
    }
}
Code:
// application/core/Public_Controller.php
class Public_Controller extends MY_Controller {
    /**
     * Class Constructor
     *
     * @access    public
     * @return    void
     */
    public function __construct()
    {
        parent::__construct();
    }
}
Code:
// application/core/Admin_Controller.php
class Admin_Controller extends MY_Controller {
    /**
     * Class Constructor
     *
     * @access    public
     * @return    void
     */
    public function __construct()
    {
        parent::__construct();
    }
}
This works:
Code:
// application/controller/welcome.php
class Welcome extends MY_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        echo 'Hello World!';
    }
}
This doesn't work:
Code:
// application/controller/welcome.php
class Welcome extends Public_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        echo 'Hello World!';
    }
}

Hope this helps, Thanks.


MY_Controller technique not working with Reactor - El Forum - 02-21-2011

[eluser]LuckyFella73[/eluser]
I guess you need to extend the config.php file - in case you
didn't allready.

Put this at the end of the file and try again:

Code:
/*
| -------------------------------------------------------------------
|  Native Auto-load
| -------------------------------------------------------------------
|
| Nothing to do with cnfig/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
*/
function __autoload($class)
{
if(strpos($class, 'CI_') !== 0)
{
  @include_once( APPPATH . 'core/'. $class . EXT );
}
}

This is part of Phil Sturgeons tutorial how to extend the CI controller.
In case you havn't read it yet:
http://philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY


MY_Controller technique not working with Reactor - El Forum - 02-21-2011

[eluser]Dom Smith[/eluser]
Perfect!! That was exactly what was wrong!

I'd been using his method in a CI 1.7.2 version and it was working and was trying to convert it to 2.0 and that's what I'd missed off! Was a while ago when I implemented it so forgot about that addition.

Thanks for the help!


MY_Controller technique not working with Reactor - El Forum - 02-22-2011

[eluser]InsiteFX[/eluser]
Mine is working with out the autoload, but maybe it is because I use HMVC.

InsiteFX


MY_Controller technique not working with Reactor - El Forum - 02-22-2011

[eluser]LuckyFella73[/eluser]
It's like you said - when you have HMVC running you don't
need to place the autoload-code in your config.php
I just checked with a fresh installation to be sure Wink