CodeIgniter Forums
Controller: calling methods from index()? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Controller: calling methods from index()? (/showthread.php?tid=3911)



Controller: calling methods from index()? - El Forum - 10-28-2007

[eluser]flokky[/eluser]
Hi community,

I'm playing the last week with CI and I like it so far.

At the moment I'm stuck and I'm not sure how to solve my problem. I want to be able to call a method within my controller from the index method. Is this possible? I'm using PHP 5

I'm getting an error: Syntax error, unexpected T_OBJECT_OPERATOR

Suppose you have a controller like this:
Code:
class MyClass extends Controller {
    
    function MyClass()
    {
        parent::Controller();
        $this->load->model('myModel', 'mymodel');
    }  

    function index()
    {
        //do initialization here
        
        this->call_method($param1, $param2); //GET THE ERROR HERE
        
        $this->load->view('myfront_view', $data);
    }
    
    function call_method($param1, $param2)
    {
        //some other calls
    }
}



Controller: calling methods from index()? - El Forum - 10-28-2007

[eluser]flokky[/eluser]
Oh my god, I saw my problem

I forgot the $ in front of this;

This solved it.


Controller: calling methods from index()? - El Forum - 10-29-2007

[eluser]maadmac[/eluser]
It'll get you every time.