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

#1
[eluser]rossmurphy[/eluser]
Is it appropriate to use a helper in a model?

#2
[eluser]Jondolar[/eluser]
Absolutely.

#3
[eluser]whobutsb[/eluser]
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?

#4
[eluser]Zorancho[/eluser]
Yes you can use $CI = & get_instance() in a helper, especially if you need to use some of the core libraries.
Code:
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.