CodeIgniter Forums

Full Version: Extends Controller Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Sarwar CSE[/eluser]
I have a controller name system which is extend MYController from core, and i want to extend it from two controller name adminpanel and user panal. like

Code:
//file Path: application/controller/system.php
class system extends MY_Controller{
     function __construct(){
         parent::__construct();
      }
    function ShowWelcomeMessage(){
         echo "welcome";
    }
}

//file Path: application/controller/adminpanel.php
class adminpanel extends system{
     function __construct(){
         parent::__construct();
      }    
}

class userpanel extends system{
     function __construct(){
         parent::__construct();
      }    
}
Quote:the url "http://localhost/test/index.php/userpanel/ShowWelcomeMessage" shows this error
Code:
Fatal error: Class 'System' not found in G:\projects\Test\application\controllers\adminpanel.php on line 2
if possible to solve this without using include(),require() in CodeIgniter like
Code:
<?php require_once(APPPATH."controllers/system.php"); ?>

Please Advice me.....

El Forum

[eluser]InsiteFX[/eluser]
The MY_Controller has to go in application/core/MY_Controller.php

El Forum

[eluser]Sarwar CSE[/eluser]
The MY_Controller has already in application/core/MY_Controller.php

Quote:My question is that is this possible In the file application/controller/adminpanel.php extends system without using
Code:
<?php require_once(APPPATH."controllers/system.php"); ?>
Code:
//file Path: application/controller/adminpanel.php
class adminpanel extends system{
     function __construct(){
         parent::__construct();
      }    
}

El Forum

[eluser]danmontgomery[/eluser]
Yes. Only files with the prefix you have defined in config.php (defaults to MY_) are automatically included. If you want to extend another controller, you would have to use autoload or include the file yourself.

El Forum

[eluser]InsiteFX[/eluser]
Here the Autoloader that noctrum is talking about!
Code:
/*
| -------------------------------------------------------------------
|  Native Autoload - by Phil Sturgeon. New Version!
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
| If using HMVC you do not need this! HMVC will autoload.
|
| Place this code at the bottom of your application/config/config.php file.
*/
function __autoload($class)
{
    if (strpos($class, 'CI_') !== 0)
    {
        if (file_exists($file = APPPATH . 'core/' . $class . EXT))
        {
            include $file;
        }

        elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT))
        {
            include $file;
        }
    }
}

InsiteFX