Welcome Guest, Not a member yet? Register   Sign In
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.




Theme © iAndrew 2016 - Forum software by © MyBB