[eluser]riwakawd[/eluser]
When I click on my radial button "no". I should update value on database to "0" from "1", But does not I think it might be some thing to do with HTML code part. Rather than the model and or controller because it updates others fine.
Note: action form temporarily removed.
Code:
<form method="post" enctype="multipart/form-data" id="form-setting" class="form-horizontal">
<ul class="nav nav-tabs" role="tablist" id="myTab">
<li class="active"><a href="#tab-general" role="tab" data-toggle="tab"><?php echo $tab_general;?></a></li>
<li><a href="#tab-store" data-toggle="tab"><?php echo $tab_store; ?></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="tab-server">
<div class="form-group">
<label class="col-sm-2 control-label"><?php echo $entry_maintenance; ?></label>
<div class="col-sm-10">
<label class="radio-inline">
<?php if ($config_maintenance) { ?>
<input type="radio" name="config_maintenance" value="1" checked="checked" />
<?php echo $text_yes; ?>
<?php } else { ?>
<input type="radio" name="config_maintenance" value="1" />
<?php echo $text_yes; ?>
<?php } ?>
</label>
<label class="radio-inline">
<?php if (!$config_maintenance) { ?>
<input type="radio" name="config_maintenance" value="0" checked="checked" />
<?php echo $text_no; ?>
<?php } else { ?>
<input type="radio" name="config_maintenance" value="0" />
<?php echo $text_no; ?>
<?php } ?>
</label>
</div>
</div>
</div>
</form>
Controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Setting extends MX_Controller {
public function __construct() {
parent::__construct();
$this->lang->load('admin/setting/setting', 'english');
$this->lang->load('admin/english', 'english');
if ($this->session->userdata('user_id') == true) {
return true;
} else {
redirect('admin');
}
}
public function index() {
$this->load->library('form_validation');
$this->form_validation->set_rules('config_name', 'Name');
$this->form_validation->set_rules('config_owner', 'Owner');
$this->form_validation->set_rules('config_address', 'Address');
$this->form_validation->set_rules('config_email', 'Email');
$this->form_validation->set_rules('config_telephone', 'Phone');
$this->document->setTitle($this->lang->line('heading_title'));
$data['heading_title'] = $this->lang->line('heading_title');
$data['action'] = site_url('admin/setting');
$data['logout'] = site_url('admin/logout');
$data['home'] = site_url('admin/dashboard');
$data['cancel'] = site_url('admin/dashboard');
$this->load->model('admin/setting/model_setting_store');
$config_meta_title = $this->model_setting_store->getSettings("config",'config_meta_title');
if (!empty($config_meta_title)) {
$data['config_meta_title'] = $config_meta_title[0]['value'];
}
$config_template = $this->model_setting_store->getSettings("config",'config_template');
if (!empty($config_template)) {
$data['config_template'] = $config_template[0]['value'];
}
$data['templates'] = array();
$directories = glob(APPPATH . 'modules/catalog/views/theme/*', GLOB_ONLYDIR);
foreach ($directories as $directory) {
$data['templates'][] = basename($directory);
}
$config_maintenance = $this->model_setting_store->getSettings("config",'config_maintenance');
if (!empty($config_maintenance)) {
$data['config_maintenance'] = $config_maintenance[0]['value'];
}
if ($this->form_validation->run() == FALSE) {
return $this->load->view('setting/settings', $data);
} else {
$config_meta_title = $this->input->post('config_meta_title');
$this->model_setting_store->editSettings("config_meta_title", $config_meta_title);
$config_maintenance = $this->input->post('config_maintenance');
$this->model_setting_store->editSettings("config_maintenance", $config_maintenance);
$config_template = $this->input->post('config_template');
$this->model_setting_store->editSettings("config_template", $config_template);
redirect('admin/dashboard');
}
}
}
Model
Code:
<?php
class Model_setting_store extends CI_Model {
function editSettings($key, $value) {
if ($key && $value) {
return $this->db->update('setting', array('value' => $value), array('key' => $key));
} else {
return false;
}
}
function getSettings($group, $key) {
if ($group && $key) {
return $this->db->get_where('setting', array('group' => $group, 'key' => $key))->result_array();
} else {
return false;
}
}
function get_config($key) {
if ($key) {
$data = $this->db->get_where('setting', array('group' => 'config', 'key' => $key))->result_array();
if (!empty($data)) {
return $data[0]['value'];
} else {
return false;
}
} else {
return false;
}
}
function set_key($key, $value) {
$checkExitKey = $this->db->get_where('setting', array('group' => 'config', 'key' => $key))->result_array();
if (!empty($checkExitKey)) {
return $this->db->update('setting', array('value'=>$value), array('group' => 'config', 'key' => $key));
}else { //Insert
$data = array(
'website_id' => 0,
'group' => 'config',
'key' => $key,
'value' => $value
);
return $this->db->insert('setting', $data);
}
}
}