Welcome Guest, Not a member yet? Register   Sign In
Help with updating to 3.0
#5

(This post was last modified: 02-20-2015, 12:26 PM by MattafixTM.)

Don't have a lot about this, if you can help please. I would be very grateful.
PHP Code:
<?php

class MY_Model extends CI_Model {

 protected 
$table_name '';
 protected 
$primary_key 'id';
 protected 
$primary_filter 'intval';
 protected 
$order_by '';
 protected 
$rules = array();
 protected 
$timestamps FALSE;
 
 function 
__Construct() {
 
// Call the CI_Model constructor
 
       parent::__construct();
 
   }
 
 public function 
get($id NULL$single FALSE) {
 if(
$id != NULL) {
 
$filter $this->primary_filter;
 
$id $filter($id);
 
$this->db->where($this->primary_key,$id);
 
$method 'row';
 }
 elseif(
$single == TRUE) {
 
$method 'row';
 }
 else {
 
$method 'result';
 }
 if(!
count($this->db->ar_orderby)) {
 
$this->db->order_by($this->order_by);
 }
 return 
$this->db->get($this->table_name)->$method();
 }
 
 public function 
get_by($where$single FALSE) {
 
$this->db->where($where);
 return 
$this->get(NULL,$single);
 }
 
 public function 
save($data$id NULL) {
 if(
$this->timestamps == TRUE) {
 
$now date('Y-m-d H:i:s');
 
$id || $data['created'] = $now;
 
$data['modified'] = $now;
 }
 
 if(
$id === NULL) {
 !isset(
$data[$this->primary_key]) || $data[$this->primary_key] = NULL;
 
$this->db->set($data);
 
$this->db->insert($this->table_name);
 
$id $this->db->insert_id();
 }
 else {
 
$filter $this->primary_filter;
 
$id $filter($id);
 
$this->db->set($data);
 
$this->db->where($this->primary_key,$id);
 
$this->db->update($this->table_name);
 }
 return 
$id;
 }
 
 public function 
delete($id) {
 
$filter $this->primary_filter;
 
$id $filter($id);
 
 if(!
$id) {
 return 
FALSE;
 }
 
 
$this->db->where($this->primary_key,$id);
 
$this->db->limit(1);
 
$this->db->delete($this->table_name);
 } 
 
 public function 
array_from_post($fields){
 
   $data = array();
 
   foreach ($fields as $field) {
 
       $data[$field] = $this->input->post($field);
 
   }
 
   return $data;
 }
}

?>

Siteconfig
PHP Code:
<?php

$router 
= &load_class('Router''core');
$dir $router->fetch_directory();

class 
Siteconfig extends MY_Model {
    public 
$rules = array(
    
'site_name' => array('field' => 'site_name''label' => 'Название сайта''rules' => 'trim'),
    
'sitedescription' => array('field' => 'sitedescription''label' => 'Фраза под заголовком''rules' => 'trim|max_length[255]'),
    
'metadescr' => array('field' => 'metadescr''label' => 'Мета-описание сайта''rules' => 'trim'),
    
'yad_client_id' => array('field' => 'yad_client_id''label' => 'Яндекс(Client ID)''rules' => 'trim'),
    
'yad_token' => array('field' => 'yad_token''label' => 'Яндекс(Token)''rules' => 'trim'),
    
'qiwi_num' => array('field' => 'qiwi_num''label' => 'QIWI(Номер без +)''rules' => 'trim'),
    
'qiwi_pass' => array('field' => 'qiwi_pass''label' => 'QIWI(Пароль)''rules' => 'trim'),
    
'wmid' => array('field' => 'wmid''label' => 'wmid''rules' => 'integer|trim|xss_clean'),
    
'WMR' => array('field' => 'WMR''label' => 'WMR''rules' => 'trim|xss_clean'),
    
'WMZ' => array('field' => 'WMZ''label' => 'WMZ''rules' => 'trim|xss_clean'),
    
'wm_pass' => array('field' => 'WMZ''label' => 'WMZ''rules' => 'trim'),
    );
    
    function 
__construct() {
        
// Call the CI_Model constructor
        
parent::__construct();
    }

    public function 
get_all() {
        return 
$this->db->get('config_data');
    }

    public function 
update_config($data) {
        
$success '0';
        foreach (
$data as $key => $value) {

            if (!
$this->save($key$value)) {
                
$success '1';
                break;
            }
        }

        return 
$success;
    }

    public function 
save($key$value) {
        
$config_data = array('key' => $key'value' => $value);
        
$this->db->where('key'$key);
        return 
$this->db->update('config_data'$config_data);
    }
}

?>
Reply


Messages In This Thread
Help with updating to 3.0 - by MattafixTM - 02-15-2015, 05:37 AM
RE: Help with updating to 3.0 - by MattafixTM - 02-15-2015, 10:35 AM
RE: Help with updating to 3.0 - by rocks - 02-15-2015, 11:31 PM
RE: Help with updating to 3.0 - by mwhitney - 02-16-2015, 10:14 AM
RE: Help with updating to 3.0 - by MattafixTM - 02-19-2015, 08:25 PM
RE: Help with updating to 3.0 - by MattafixTM - 02-22-2015, 08:53 AM
RE: Help with updating to 3.0 - by dbui - 02-22-2015, 11:06 PM
RE: Help with updating to 3.0 - by MattafixTM - 02-23-2015, 06:18 AM
RE: Help with updating to 3.0 - by mwhitney - 02-24-2015, 01:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB