Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Updating Database
#1

[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">
&lt;?php foreach ($templates as $template) { ?&gt;
&lt;?php if ($template == $config_template) { ?&gt;
<option value="&lt;?php echo $template; ?&gt;" selected="selected">&lt;?php echo $template; ?&gt;</option>
&lt;?php } else { ?&gt;
<option value="&lt;?php echo $template; ?&gt;">&lt;?php echo $template; ?&gt;</option>
&lt;?php } ?&gt;
&lt;?php } ?&gt;
</select>
</div>
</div>

<div class="form-group">
<button type"submit" value="" class="btn btn-md btn-primary">Save</button>
</div>
  
&lt;?php echo form_close();?&gt;


Messages In This Thread
[SOLVED] Updating Database - by El Forum - 07-13-2014, 10:52 PM
[SOLVED] Updating Database - by El Forum - 07-14-2014, 01:57 AM
[SOLVED] Updating Database - by El Forum - 07-14-2014, 02:12 AM
[SOLVED] Updating Database - by El Forum - 07-14-2014, 03:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB