[eluser]riwakawd[/eluser]
[quote author="Tim Brownlaw" date="1405328252"]Where would you prefer to save your current theme setting?
The Database OR the Config file.. Having both is silly because, in your script where does it decide where it should go and look?
You can of course update the config setting (Not the config file setting ) from the Database each time a page is loaded.
In your database you would have an options or settings table which you can read in each time and store in memory and write a method to retrieve those kinds of thing from it... That way it's only one DB Select instead of performing a DB Select each time you need it throughout the current script. That's beneficial for things you need to know more than once during the running of the script.
You could have it so if there's been no setting or a valid setting in the options table, to go and read the config setting as the default OR better is to set the actual default theme in the options table on installation (preferred method).
There's a bunch of ways to do things.
But I see no point in setting a value in the DB AND rewriting your config file for a theme setting... Unless you have some reason I cannot see!
Check your model - I see one too many } (on the end)
Check your view - The first line is wrong! Typo on action and incomplete <?php .... ?>
[/quote]
I have almost got it working now can update database model just need now to make my $store_info['config_template'] to work with the config item.
And also just have to work out how to make it row id to stop changing but just to be fixed.
Code:
<?php
class Setting extends CI_Controller {
public function index() {
$this->load->model('setting_model');
if ($this->input->server('REQUEST_METHOD') == 'POST') {
$this->setting_model->editSetting('config', $this->input->post(), $store_id);
redirect('setting');
}
if (null !==($this->input->post('config_template'))) {
$data['config_template'] = $this->input->post('config_template');
} elseif (null !==($store_info['config_template'])) {
$data['config_template'] = $store_info['config_template'];
} else {
$data['config_template'] = '';
}
$data['templates'] = array();
$directories = glob(DIR_APPLICATION . 'views/theme/*', GLOB_ONLYDIR);
foreach ($directories as $directory) {
$data['templates'][] = basename($directory);
}
return $this->load->view('setting/setting', $data);
}
public function validate() {
}
}
Model edit part
Code:
public function editSetting($group, $data, $store_id = 0) {
$this->db->query("DELETE FROM " . $this->db->dbprefix . "setting WHERE store_id = '" . (int)$store_id . "' AND `group` = " . $this->db->escape($group) . " ");
foreach ($data as $key => $value) {
if (!is_array($value)) {
$this->db->query("INSERT INTO " . $this->db->dbprefix . "setting SET store_id = '" . (int)$store_id . "', `group` = " . $this->db->escape($group) .", `key` = " . $this->db->escape($key) . ", `value` = ". $this->db->escape($value) ." ");
} else {
$this->db->query("INSERT INTO " . $this->db->dbprefix . "setting SET store_id = '" . (int)$store_id . "', `group` = " . $this->db->escape($group) . ", `key` = " . $this->db->escape($key) . ", `value` = ". $this->db->escape(serialize($value)) . ", serialized = '1'");
}
}
}