CodeIgniter Forums
How to use MY_controller with ci 2.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: How to use MY_controller with ci 2.0 (/thread-38365.html)



How to use MY_controller with ci 2.0 - El Forum - 02-06-2011

[eluser]chefnelone[/eluser]
I used to use MY_controller in this way in ci 1.7 but isn't working in ci 2.0
No error message, just a blank page...

In a fresh ci installation:
application/controller/welcome.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends MY_Controller{

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

    function index()
    {
        $this->load->view('welcome_message');
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */


library/MY_controller.php
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

    class  MY_Controller extends CI_Controller{
    
    
        function __construct(){        
        


        }

}

What am I missing?
Thanks


How to use MY_controller with ci 2.0 - El Forum - 02-06-2011

[eluser]mejlo[/eluser]
Hi,
move application/libraries/MY_Controller.php to application/core/MY_Controller.php
When you extend core class, you must put it in "core" directory


How to use MY_controller with ci 2.0 - El Forum - 02-06-2011

[eluser]chefnelone[/eluser]
[quote author="mejlo" date="1297040342"]Hi,
move application/libraries/MY_Controller.php to application/core/MY_Controller.php
When you extend core class, you must put it in "core" directory[/quote]

I've done what you said, but I get this error message:



A PHP Error was encountered

Severity: Notice

Message: Undefined property: Welcome::$load

Filename: controllers/welcome.php

Line Number: 12


Line 12 is:
$this->load->view('welcome_message');


How to use MY_controller with ci 2.0 - El Forum - 02-06-2011

[eluser]cideveloper[/eluser]
According to the code you showed, you are missing a line in your MY_Controller

Code:
class  MY_Controller extends CI_Controller{
    function __construct(){
        parent::__construct(); // This line needs to be there
    }
}



How to use MY_controller with ci 2.0 - El Forum - 02-07-2011

[eluser]chefnelone[/eluser]
[quote author="cideveloper" date="1297075151"]According to the code you showed, you are missing a line in your MY_Controller

Code:
class  MY_Controller extends CI_Controller{
    function __construct(){
        parent::__construct(); // This line needs to be there
    }
}
[/quote]
Thanks, I modified the code for this post, then I forgot to change.


How to use MY_controller with ci 2.0 - El Forum - 02-16-2011

[eluser]Stefano G[/eluser]
As a suggestion, maybe it could be a good idea to put the information of "moving the MY_Controller and MY_Model -and everything that extends the core classes- into the application/core directory" in the UPGRADING section of the new user guide Smile