I have made a library class in php which can get data from my database table settings.
I can get information if it is not serialized.
But I would like to know on my get function what would be best method to be able to return unserialise information just incase it is serialized.
<?php
class Settings {
private $data = array();
public function __construct() {
$this->CI =& get_instance();
}
public function get($key = NULL) {
if ($key != NULL) {
$value = $this->get_where($key);
return $value;
} else {
return FALSE;
}
}
public function get_where($key = NULL) {
if ($key != NULL) {
$store_id = $this->store_id();
$result = $this->CI->db->get_where($this->CI->db->dbprefix . 'setting', array('store_id' => $store_id, 'group' => 'config', 'key' => $key));
if ($result != FALSE AND $result->num_rows() > 0) {
$data = $result->result_array();
return $data[0]['value'];
} else {
return FALSE;
}
} else {
return FALSE;
}
}
public function store_id() {
$store_id = $this->CI->uri->segment(5);
if ($store_id !== TRUE) {
return $store_id;
} else {
return FALSE;
}
}
}