Created
April 19, 2018 08:00
-
-
Save teramuza/5d1f83528787f9789f02deaec684e62d to your computer and use it in GitHub Desktop.
Undefined index : notif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function update(){ | |
$data['title'] = "Update Artikel"; | |
$data['session_user'] = $this->session_user; | |
if(empty($this->uri->segment('3'))){ redirect('articles');} | |
$id = $this->uri->segment('3'); | |
$data['articles'] = $this->articlesModel->getArticleWhere($id); | |
$this->load->library('upload'); | |
if(count($_POST)){ | |
$title = str_replace(' ','-',$this->input->post('title')); | |
$config['upload_path'] = './public/images/articles'; //path folder | |
$config['allowed_types'] = 'jpg|png|jpeg'; //type yang dapat diakses bisa anda sesuaikan | |
$config['file_name'] = $title.'_img.jpg'; //nama yang terupload nantinya | |
$config['overwrite'] = true; | |
$this->upload->initialize($config); | |
if(!empty($_FILES['image']['name'])){ | |
if ($this->upload->do_upload('image')) | |
{ | |
$img = $this->upload->data(); | |
$image = $img['file_name']; | |
$data['notif'] = $this->articlesModel->updateArticles($id,$image); | |
} | |
}else{ | |
$data['notif'] = $this->articlesModel->updateArticles($id,$this->input->post('oldImage')); | |
} | |
if($data['notif']['type'] == 'success'){ | |
$data['articles'] = ''; | |
echo '<script>setTimeout(function(){ window.location.href = "'.base_url('articles').'"; }, 1000);</script>'; | |
} | |
} | |
$this->load->view('includes/header', $data); | |
$this->load->view('dashboard/article_edit', $data); | |
$this->load->view('includes/footer', $data); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function updateArticles($id, $image){ | |
$notif = array(); | |
$data = array( | |
'title' => $this->input->post('title'), | |
'tags' => $this->input->post('tags'), | |
'pic' => $image, | |
'contents' => $this->input->post('contents'), | |
'is_posted'=> $this->input->post('is_posted') ? : 0 | |
); | |
$this->db->where('article_id',$id); | |
$this->db->update('articles',$data); | |
if ($this->db->affected_rows() > 0) { | |
$notif['message'] = 'Saved successfully'; | |
$notif['type'] = 'success'; | |
unset($_POST); | |
} else { | |
$notif['message'] = 'Something wrong !'; | |
$notif['type'] = 'danger'; | |
} | |
return $notif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment