How to use MY_controller with ci 2.0

#1
[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

#2
[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

#3
[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');

#4
[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
    }
}

#5
[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.

#6
[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.