Skip to content

Instantly share code, notes, and snippets.

@rsmarshall
Created May 14, 2012 16:06
Show Gist options
  • Save rsmarshall/2694768 to your computer and use it in GitHub Desktop.
Save rsmarshall/2694768 to your computer and use it in GitHub Desktop.
what's going wrong
<?php
/**
* Supplier management library
* @package Suppliers
* @author Ryan Marshall <ryan@irealms.co.uk>
*/
class Suppliers_model extends BF_Model {
protected $table = 'bf_supplier_details';
protected $key = 'id';
protected $alt_table = 'bf_supplier_pricing';
protected $alt_key = 'id';
protected $soft_deletes = false;
protected $date_format = 'int';
protected $set_created = false;
protected $set_modified = false;
public function __construct() {
}
/**
* Save supplier
* @param integer $id Supplier id
* @return boolean
*/
public function save_supplier($id = NULL)
{
$data = array(
'sup_account' => $this->input->post('sup_account'),
'sup_name' => $this->input->post('sup_name'),
'ftp_host' => $this->input->post('ftp_host'),
'ftp_port' => $this->input->post('ftp_port'),
'ftp_user' => $this->input->post('ftp_user'),
'ftp_pass' => $this->input->post('ftp_pass'),
'ftp_directory' => $this->input->post('ftp_directory'),
'comp_file' => $this->input->post('comp_file'),
'uncomp_file' => $this->input->post('uncomp_file'),
'feed_separator' => $this->input->post('feed_separator'),
'n_ftp_directory' => $this->input->post('n_ftp_directory'),
'n_comp_file' => $this->input->post('n_comp_file'),
'n_uncomp_file' => $this->input->post('n_uncomp_file'),
'n_feed_separator' => $this->input->post('n_feed_separator'),
'date_format' => $this->input->post('date_format')
);
if ($id)
{
return $this->update($id, $data);
}
else
{
return $this->insert($data);
}
}
public function search()
{
if ($this->input->post('submit'))
{
if ($this->form_validation->run($this, 'search_feeds') !== FALSE)
{
$this->set_table(FALSE);
$query = $this->find_all_by('id', 1);
$this->set_table();
return $query;
}
}
else
{
return NULL;
}
}
/**
* Set table method for multiple tables in model
* @link http://blog.s-vizion.com/2012/codeigniter/a-quick-tip-on-codeigniter-and-bonfires-model-for-evil/
* @param boolean $table Set primary or alt table
* @return \Suppliers_model
*/
public function set_table ($table = TRUE)
{
if ($table === TRUE)
{
$this->table = 'bf_supplier_details';
$this->key = 'id';
} else {
$this->table = $this->alt_table;
$this->key = $this->alt_key;
}
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment