Welcome Guest, Not a member yet? Register   Sign In
How to create sub base controller class and the directory structure of it?
#1

[eluser]Unknown[/eluser]
Hi Guys,

I have created a sub base controller class included on application/libraries folder <-- is this right?

Code:
abstract class MY_CMSGenBaseController extends Controller {
    
    function Controller() {
        parent::Controller();
    }

}

So that on my application controller class it should be
Code:
class Welcome extends MY_CMSGenBaseController {
    
    function __construct() {
        parent::Controller();
    }
    
}

Now, the script is unable to find the "MY_CMSGenBaseController" class. How can I able to attain this setup? Please provide some directory structure of it?

TIA!
#2

[eluser]Hannes Nevalainen[/eluser]
Your constructor is wrong.
Code:
abstract class MY_CMSGenBaseController extends Controller {
    
    function Controller() {
        parent::Controller();
    }

}
Try to do this instead:
Code:
abstract class MY_CMSGenBaseController extends Controller {
    
    function MY_CMSGenBaseController() {
        parent::Controller();
    }

}
And change your Controller to:
Code:
class Welcome extends MY_CMSGenBaseController {
    function Welcome(){
        parent:: MY_CMSGenBaseController();
    }
}
#3

[eluser]Sumon[/eluser]
Sorry to say i follow your way but getting errors. May be i m wrong.
here is my libraries\my_base_class.php
Code:
&lt;?php
abstract class My_base_class extends Controller{
    function My_base_class() {
        parent::Controller();
    }
    function test()
    {
        echo "inside library-> my_base_class class. function name test";
    }
}
?&gt;

and controllers\my_class.php
Code:
&lt;?php
class My_class extends My_base_class {
    function My_class() {
        parent::my_base_class();
    }
}
?&gt;

Moreover, i have tried with autoload my_base_class in config\autoload.php.
#4

[eluser]wiredesignz[/eluser]
Don't use MY_ unless you are extending a CI core library.
#5

[eluser]Hannes Nevalainen[/eluser]
I'm sorry I forgot you need to call your file MY_Controller.php
Your MY_Controller class should look like this:
Code:
abstract class MY_Controller extends Controller{
  
    function MY_Controller(){
       parent::Controller();
    }
}
abstract class MY_CMSGenBaseController extends Controller {
    
    function MY_CMSGenBaseController() {
        parent::Controller();
    }

}
#6

[eluser]Unknown[/eluser]
Thanks for all of your replies guys. I found the solution here: http://ellislab.com/forums/viewthread/68446/

Thanks again!
#7

[eluser]vinod_ci[/eluser]
Hi
I have to create more than one cotrollers.
Because currently, In my controller the code size is beyound 4000 lines.
How i put this number of functions in seperate files and again make call from main controller to this functions.

I have tried one solution for this, the files are:

1. made one base controller
/application/libraries/

class MY_Controller extends Controller {

function MY_Controller() {
parent::Controller();
}
function test_vinod($xyz)
{
echo "hi hello";
echo $xyz;
}

}
2. for developer1

/application/libraries/

&lt;?php

class devloper1 extends MY_Controller {

function devloper1() {
parent::MY_Controller();

}
function homepage()
{
echo "vinod";
}
}

same as above i want to create more classes like developer2.....3,4,5
In which developer put his own functions


3. And finally my base controller from which i can call these functions from developers

&lt;?php

class Welcome extends MY_Controller {

function Welcome()
{
parent::MY_Controller();


}

function index()
{
$this->test_vinod('abc');

$this->load->library('devloper1');
$this->devloper1->homepage();
// likely above statement can i load more libraries (developers)
// and call the functions

}

}


My question: is it way to make compact and clear code?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB