CodeIgniter Forums
Call function from another function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Call function from another function (/thread-7259.html)



Call function from another function - El Forum - 04-01-2008

[eluser]luukskywalker[/eluser]
I have a small question.

I have 2 functions in 1 controller
Say Function A and Function B

Is it possible to call function B at the end of Function A?
If so, how is this done?

I know i can call a view but i don't want a view at the end of function A


Call function from another function - El Forum - 04-01-2008

[eluser]jamesf[/eluser]
If the second function is an action with its own view you could redirect to that action
Code:
redirect('controller/functionb');

Or if the function is just some controller logic you can call the method using:

Code:
$this->function_b();



Call function from another function - El Forum - 04-01-2008

[eluser]luukskywalker[/eluser]
great
This works fine
Thank you!


Call function from another function - El Forum - 04-01-2008

[eluser]jamesf[/eluser]
No problem,

Also if the method is just controller logic then put an underscore before the function name so that it can't be accessed from a URL e.g. http://website/controller/function_b

Code:
$this->_function_b();

This "http://website/controller/function_b" will no longer work.


Call function from another function - El Forum - 04-03-2008

[eluser]luukskywalker[/eluser]
is it also possible to send variables from function a to function b?

Because i want something like this(this is just an example):
Code:
Function_a(){
  
  $foo = "1";
  $this->_function_b($foo);
}

Function_b(){
if($foo){
      
echo $foo+1;

}else{

$foo = "10";
echo $foo;
}