Try this.
Instead of instantiating a new Article_Model
in the do_upload
method, simply return the image name from the do_upload
method, and set the url property of the Article_Model
before saving it to the database.
public function add_article($id = NULL)
{
$articles = new Article_model();
$article = $articles->where('id', $id)->get();
$article->title = $this->input->post('title');
$article->text = $this->input->post('text');
// Try to upload the image
if ($this->input->post('submit'))
{
$article->url = $this->do_upload();
}
if ($article->save())
{
echo '<p>You have successfully added an article</p>';
redirect('admin/article/');
}
else
{
echo '<p>' . $article->error->string . '</p>';
}
}
public function do_upload()
{
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->gallery_path,
);
$this->load->library('upload' , $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
return $image_data['file_name'];
}