Welcome Guest, Not a member yet? Register   Sign In
A controller function can load another controllers??
#1

[eluser]atoleon[/eluser]
Hi

Can i load a controller like i load a view?
#2

[eluser]WanWizard[/eluser]
In standard CI, no, you can't.

You can with a Modular solution, like Modular CI.
#3

[eluser]ShoKatoo[/eluser]
[quote author="atoleon" date="1288037498"]Hi

Can i load a controller like i load a view?[/quote]

Please give an example... Is it something like calling a function declared in controller A from controller B?
If that is so you can do this:

Controller A

Code:
<?php
class Conta extends Controller {
    function Conta(){
        parent::Controller();
    }
    function index(){
    }
    function test_function(){
        echo("It's working!!!");
    }
}
/* End of file conta.php */
/* Location: ./application/controllers/ */
Controller B
Code:
<?php
require_once("conta.php");
class Contb extends ContA{

    function Contb(){
        parent::Conta();
    }

    function index(){
        
    }
}
/* End of file contb.php */
/* Location: ./application/controllers/ */
It works fine and I belive that it is the best practice.
You can now call function test_function() like http://localhost/contb/test_function even if you have no test_function() in Contb controller. The Contb controller extends the Conta controller inheriting all its function/methods.

Have Phun! Smile
#4

[eluser]WanWizard[/eluser]
That's not one controller calling another, that is extending a class. Totally different concept.
#5

[eluser]ShoKatoo[/eluser]
[quote author="ShoKatoo" date="1288045763"][...] The Contb controller extends the Conta controller inheriting all its function/methods.[...][/quote]
Exactly what I said Tongue
#6

[eluser]tonanbarbarian[/eluser]
if you find you have code in one controller that you would like to access from another controller then you probably need to move that common code into a library and then call the library from each controller




Theme © iAndrew 2016 - Forum software by © MyBB