CodeIgniter Forums
Access functions across controllers? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Access functions across controllers? (/showthread.php?tid=10102)



Access functions across controllers? - El Forum - 07-18-2008

[eluser]Unknown[/eluser]
How do I access functions from one controller in another one?


Access functions across controllers? - El Forum - 07-20-2008

[eluser]Michael;[/eluser]
You do not. If you need a function across multiple controllers it will need to be placed in a library. I recommend you create a "common" library that allows you to store these functions in. Works best for these types of cases.

If you end up with a few related functions then you should probably create yourself a new library for those functions ... like for example if you have 3-4 functions specifically for date/time manipulation.

Michael


Access functions across controllers? - El Forum - 07-20-2008

[eluser]nmweb[/eluser]
Search for HMVC and Wick for this kind of functionality. There are some perfectly valid causes for this behaviour.


Access functions across controllers? - El Forum - 07-20-2008

[eluser]Derek Allard[/eluser]
Just for clarity, (I'm not sure what you mean by "access" functions) but you can use
Code:
class Foo extends Controller {

    function one()
    {
        $this->two();
    }


    function two()
    {
        // do something
    }
}