Welcome Guest, Not a member yet? Register   Sign In
$function() ?
#1

[eluser]Boyz26[/eluser]
Hi everyone,

Is there any way I can convert a string variable to a function?
I am storing a series of actions in the database that will be called later.

Code:
function recipe($id) {
$this->db->where('recipe_id', $id);
$query = $this->db->get('actions');
foreach($query->result() as $row):
//my question: can I do any of these?
  $actionName = $row->actionName;
  $this->$actionName();
//or..
  convertToFunction($actionName);
//or..
  if($actionName == 'fryAnEgg') { $this->fryAnEgg() }
  elseif($actionName== 'bakeCookie') { $this->bakeCookie() }
//and so on..
endforeach;
}

function fryAnEgg() {
  //complex function
}

function bakeCookie() {
//another function
}

I will be having many many actions, so I don't want to make a long elseif list..

Thank you!!


Messages In This Thread
$function() ? - by El Forum - 09-01-2008, 12:21 AM
$function() ? - by El Forum - 09-01-2008, 12:41 AM
$function() ? - by El Forum - 09-01-2008, 01:14 AM
$function() ? - by El Forum - 09-01-2008, 01:19 AM
$function() ? - by El Forum - 09-01-2008, 01:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB