Welcome Guest, Not a member yet? Register   Sign In
Controller: calling methods from index()?
#1

[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
    }
}
#2

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

I forgot the $ in front of this;

This solved it.
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB