codeigniter: helper function to call library or model function in view

Hi I am back again,

This time with two helper function that lets you call any function from any model or library, given you already have the model or library loaded into the instance.

This one calls a library function with a single parameter being passed.

  1. if(!function_exists(‘call_lib_func’)){
  2.  function call_lib_func($library_name, $function_name, $parameters=null){
  3.   $ci = &get_instance();
  4.   $ci->load->library($library_name);
  5.   return $ci->$library_name->$function_name($parameters);
  6.  }
  7. }

The next one calls a model function with a single parameter being passed.

  1. if(!function_exists(‘call_mod_func’)){
  2.  function call_mod_func($model_name, $function_name, $parameters=null){
  3.   $ci = &get_instance();
  4.   $ci->load->model($model_name);
  5.   return $ci->$model_name->$function_name($parameters);
  6.  }
  7. }

As of now multiple parameter are not yet supported but I will soon post an extension of these two functions that will support multiple parameters. If you choose to use any of these functions feel free to use but a link back to my site is appreciated :)

thanks,

thephpx

Share