codeigniter-base-model
codeigniter-base-model copied to clipboard
Select Only One Field
trafficstars
Is it possible to return only one field so that something like this works?
$this->tagline = $this->setting->get_by(array('name' => 'tagline'))->select('value');
$this->tagline = $this->setting->get_by(array('name' => 'tagline'))->select('value')->value; ?
you can't do that, there will be an error.
Fatal error: Call to undefined method stdClass::select()
I end up just creating one custom function to get the value.
public function get_value($name) {
if (empty($name)) {
return;
}
$r = $this->db->select('value')
->where('name', $name)
->get($this->_table);
if (empty($r->row()->value)) {
return;
}
return $r->row()->value;
}
This only works in a key-value pair table though. Although this won't be reusable in all cases, it would be nice if this is somehow built-in in the library though.
Yeap, sorry, my mistake =) select() is not nessesary