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

About thephpx

I am a freelance web application developer. I work with PHP5 and MySQL. Most of my projects are done using the codeIgniter framework.I am also working towards moving onto the Zend Framework. I follow agile development methodology and manage my projects throuh SCRUM based approach. Apart from being a developer I am also the CEO of a small web identity and application development firm located in dhaka, bangladesh. The firm known as 'implode impressions' also follows agile development techniques and works under the SCRUM based approach.

One response to “codeigniter: helper function to call library or model function in view

  1. this post is very usefull thx!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>