Welcome Guest, Not a member yet? Register   Sign In
Display Active Template First
#5

[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';
  }
}


Messages In This Thread
Display Active Template First - by El Forum - 09-01-2014, 09:00 PM
Display Active Template First - by El Forum - 09-01-2014, 09:35 PM
Display Active Template First - by El Forum - 09-01-2014, 10:32 PM
Display Active Template First - by El Forum - 09-01-2014, 11:00 PM
Display Active Template First - by El Forum - 09-01-2014, 11:32 PM
Display Active Template First - by El Forum - 09-02-2014, 01:03 AM
Display Active Template First - by El Forum - 09-02-2014, 01:59 AM
Display Active Template First - by El Forum - 09-02-2014, 02:15 AM
Display Active Template First - by El Forum - 09-02-2014, 05:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB