0

I'm been trying to send a dynamic number of arguments to a function in Codeigniter and have been running into a wall with call_user_func_array.

One error I'm getting "Undefined property: Account::$callShowMessage" is making me wonder if it's even possible to refer to a function in another file with call_user_func_array/CodeIgniter.

If anyone could help point me into the right direction, it would be greatly appreciated.

Array:

Array ( [0] => Current password is incorrect [1] => New passwords don't match )

Controller Excerpt:

$this->session->set_flashdata('msg', call_user_func_array($this->generic_model->callShowMessage, $msg));

Function:

public function callShowMessage()
{   

$args = func_get_args();  

foreach ($args as $key => $value) {  
    $msg .= "$value<br />";  
}   
$msg = addslashes($msg);
return "<script type='text/javascript'>$(document).ready(function() { showMessage('$msg') });</script>";
}
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
jsuissa
  • 1,754
  • 6
  • 30
  • 64

1 Answers1

5
call_user_func_array(array($this->generic_model, 'callShowMessage'), $msg)

To pass a method of an object as callback, use the above array syntax with the object and the name of the method. See http://php.net/manual/en/language.pseudo-types.php#language.types.callback(dead link).

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
deceze
  • 510,633
  • 85
  • 743
  • 889