CodeIgniter Forums
functions within controllers - 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: functions within controllers (/showthread.php?tid=23725)



functions within controllers - El Forum - 10-20-2009

[eluser]jbuda[/eluser]
i have a function within a controller called 'updateStatus()'

using the syntax : updateStatus()

im trying to call this function from another function within the controller, but it keep erroring sating that updateStatus() is not defined.

i check spelling and case, and it is exactly the sam.

Am i supposed to use something like this to call the function within the controller $this->updateStatus()???


functions within controllers - El Forum - 10-20-2009

[eluser]sl3dg3hamm3r[/eluser]
[quote author="jbuda" date="1256072249"]Am i supposed to use something like this to call the function within the controller $this->updateStatus()???[/quote]

yes.


functions within controllers - El Forum - 10-20-2009

[eluser]jbuda[/eluser]
i tried that... but the following error in Apache
PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR


functions within controllers - El Forum - 10-20-2009

[eluser]khagendra[/eluser]
This can be done by two ways.

1. By using the redirect() function of the url helper. for this the helper url need to be load in the controller.

2. $this->functionName();

Here is an example that demonstrate both the ways

Code:
class Example extends Controller {
    
    function Example()
    {
        parent::Controller();
        
        $this->load->helper('url');
    }
    
    function index()
    {
        $this->show();
    }
    
    function show1()
    {
        echo "two";
    }
    
    function show()
    {
      redirect('example/show1');
    }
}

Try this, it will work.

Quote:Note: the url helper only need to load if u wnat to use redirect('controller/function')



functions within controllers - El Forum - 10-20-2009

[eluser]n0xie[/eluser]
[quote author="jbuda" date="1256072769"]i tried that... but the following error in Apache
PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR[/quote]
add an ';'