Welcome Guest, Not a member yet? Register   Sign In
function help [solved]
#1

[eluser]superfake123[/eluser]
Hello,

How/where can I put this function so that I can access it from within any controller/model or view etc?

Code:
function get_setting($setting)
{
$query = $this->db->where('setting_name',$setting)->get('settings')->row();
return $query->value;
}

I tried putting it in a helper but the db class doesn't work from helpers I guess?


Thanks!
#2

[eluser]CroNiX[/eluser]
Lots of ways, actually. You can extend the Controller with MY_Controller and put it there. You could create a library. You could also put it in a helper, but not the way you are doing it. A helper is a regular php function, so it doesn't know anything about CI ($this) unless you bring the CI superglobal into it, like:
Code:
function get_setting($setting)
{
  $CI =& get_instance();  //now access CI using $CI instead of $this
  $query = $CI->db->where('setting_name',$setting)->get('settings')->row();
  return $query->value;
}

#3

[eluser]superfake123[/eluser]
oh I like the $CI =& get_instance() way! thank you very much!




Theme © iAndrew 2016 - Forum software by © MyBB