[eluser]invision[/eluser]
Hello,
I am currently using the following to create a news entry in my database.
The Controller also moves a file to my server.
This works great.
However, I'd like it so when the news entry is created, the
$file_name value is inserted into the
news table along with the rest of the post data.
Can anyone please help me to achieve this?
Model
Code:
function addNews($file_name){
$now = date("Y-m-d H:i:s");
$data = array(
'title' => $this->input->post('title'),
'slug' => $this->input->post('slug'),
'status' => $this->input->post('status'),
'body' => $this->input->post('body'),
'category_id' => '1',
'user_id' => $_SESSION['userid'],
'img_header' => '1' // this is where my file name should go, instead of '1'
);
$this->db->insert('news', $data);
}
Controller
Code:
function create(){
if ($this->input->post('title')){
$config['upload_path'] = '../uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
}
//$this->MNews->addNews();
$file_name = !empty($data['upload_data']) ? $data['upload_data']['file_name'] : NULL ;
$this->MNews->addNews($file_name);
$this->session->set_flashdata('message','News created');
redirect('admin/news/index','refresh');
} else {
$data['title'] = "Create News";
$data['main'] = 'admin_news_create';
$this->load->vars($data);
$this->load->view('dashboard');
}
}
Many thanks for any help you can provide.