[eluser]riwakawd[/eluser]
[quote author="Tim Brownlaw" date="1409637624"]It seems you are telling it what value it's meant to be reading without actually reading the value from the DB!!!!
Now I know you are using HMVC from your last post...So WHY do you insist on using libraries and not use Models within your module... This settings stuff could go into a Settings module... to keep it all nice and tidy.
Or a Template Module... But it's definitely a candidate for using in a Model.
So this answer is based upon you having it in a model somewhere...
Code:
/**
* Read back the Current Template Name
*
* @return string template name or an error message
*/
public function getTemplate() {
$this->db->select('value');
$this->db->where('group','config');
$this->db->where('key','config_template');
$result = $this->db->get('setting');
if($result !== FALSE AND $result->num_rows() > 0)
{
$row = $query->row(); // I've just broken this out from what you had
return $row->value;
}
else
{
return 'Entry Not Found';
}
}
I am assuming that your setting table has the fields value,group and key
[/quote]
I re changed part on the controller to what below but now get error from model.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: query
Filename: setting/model_setting_store.php
Line Number: 66
Fatal error: Call to a member function row() on a non-object in C:\Xampp\htdocs\codeigniter\project-2\application\modules\admin\models\setting\model_setting_store.php on line 66
Controller
Code:
$this->load->model('admin/setting/model_setting_store');
if($this->model_setting_store->config_template()) {
$data['config_template'] = $this->input->post('config_template');
} else {
// Should display current theme/template
$data['config_template'] = $this->model_setting_store->getTemplate();
}
Model
Code:
function config_template() {
$data = array(
'setting_id' => "10",
'website_id' => "0",
'group' => "config",
'key' => "config_template",
'value' => $this->input->post('config_template')
);
$this->db->update('setting', $data);
}
public function getTemplate() {
$this->db->select('value');
$this->db->where('group','config');
$this->db->where('key','config_template');
$result = $this->db->get('setting');
if($result !== FALSE AND $result->num_rows() > 0) {
$row = $query->row(); // I've just broken this out from what you had
return $row->value;
}else{
return 'Entry Not Found';
}
}