Call function from another function

#1
[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

#2
[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();

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

#4
[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.

#5
[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;
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.