[eluser]riwakawd[/eluser]
I am making a form which lets me select what theme I would like to use and it should update the database and then update my config file.
In my config file I have made $config['config_template'] = $template;
Config File
Setting.php
Code:
<?php
// $config['config_template'] = "default";
$config['config_template'] = $template;
I am trying to get it so when I choose what theme I am after it will update the database with value i.e name of theme.
And make it so the config item stays on the theme selected from database.
How do I make it work like that? I can see the themes fine in select form.
Controller
Code:
<?php
class Setting extends CI_Controller {
public function index() {
$this->config->item('setting');
$this->load->model('setting_model');
if (null !==($this->input->post('config_template'))) {
$data['config_template'] = $this->input->post('config_template');
} else {
$data['config_template'] = $this->config->set_item('config_template', $template);
}
$data['templates'] = array();
// DIR_APPLICATION is defined As APPPATH FOR MULTI CI INSTALL.
$directories = glob(DIR_APPLICATION . 'views/theme/*', GLOB_ONLYDIR);
foreach ($directories as $directory) {
$data['templates'][] = basename($directory);
}
return $this->load->view('setting/setting', $data);
}
}
Model
Code:
<?php
class Setting_model extends CI_Model {
public function editSetting() {
$this->db->set('group', 'config');
$this->db->set('key', 'config_template');
$this->db->set('value', $this->input->post('config_template'));
$this->db->update($this->db->dbprefix, 'setting');
}
}
}
View
Code:
<form method="post" acti echo base_url('setting');?>">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-template">Template</label>
<div class="col-sm-10">
<select name="config_template" id="input-template" class="form-control">
<?php foreach ($templates as $template) { ?>
<?php if ($template == $config_template) { ?>
<option value="<?php echo $template; ?>" selected="selected"><?php echo $template; ?></option>
<?php } else { ?>
<option value="<?php echo $template; ?>"><?php echo $template; ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<button type"submit" value="" class="btn btn-md btn-primary">Save</button>
</div>
<?php echo form_close();?>