• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Helpers used in models

Is it appropriate to use a helper in a model?


I will add on to this question. What about in controllers? When would you use a helper rather than a library? I personally use libraries if Im going to write methods where classes needed and use helpers where i just need straight methods/functions.

One more question is it alright to use the $CI =& get_instance(); with in helpers?

Yes you can use $CI = & get_instance() in a helper, especially if you need to use some of the core libraries.
function do_something_or_else()
$CI = & get_instance();
$user_id = $CI->session->userdata('user_id');
I use helpers for logic in views mostly, but sometimes helpers like URL is very helpful in controller especially the base_url() method or if you are printing HTML in a Controller AJAX method.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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