Код: Выделить всё
class Tracking extends CI_Controller {
public $Data = array();
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->language('tracking', $this->config->item('language'));
$this->load->model('tracking_model');
//$data['tracking'] = $results['rows'];
}
/*******************************************************
--- GET THE DEFAULT LIST VIEW --------------------------
*******************************************************/
function index()
{
$this->Data['TrackingArray'] = (array)$this->tracking_model->getTracks();
$this->load->view('tracking_view', $this->Data);
}
/*******************************************************
--- ADD NEW --------------------------------------------
*******************************************************/
function add()
{
if($_SERVER['REQUEST_METHOD']=='POST'){
$this->_validation();
if ($this->form_validation->run() == FALSE)
{
$this->Data = array_merge((array) $this->input->post(), (array) $this->Data);
$this->Data['SysError'] = $this->lang->line('customers_validate_fail');
$this->load->view('Form', $this->Data);
}else{
$Results = $this->tracking_model->addTracks();
$this->session->set_flashdata('SysOk', $this->lang->line('tracking_add_success'));
redirect('tracking', 'refresh');
die();
}
}else{
$this->load->view('Form', $this->Data);
}
}
Код: Выделить всё
function addTracks()
{
$Data['Food'] = $this->input->post('Food');
$Data['Calories'] = $this->input->post('Calories');
$Data['TotalFat'] = $this->input->post('TotalFat');
$Data['DietaryFiber'] = $this->input->post('DietaryFiber');
$Data['ServingSize'] = $this->input->post('ServingSize');
$Data['NumberOfServings'] = $this->input->post('NumberOfServings');
$Data['TotalPoints'] = $this->input->post('TotalPoints');
if($this->db->insert('tracking', $Data))
{
return $this->db->insert_id();
}else{
return FALSE;
}
}
<
Введите информацию о еде
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/17735227/codeigniter-cant-get-values-from-form-to-database[/url]