I was coding some project and then i went into some problem about part of code. I was bumping my head around, and then i found out where is the problem. Here are two versions of code, first one works, second dont. Second part of code just activate else block, it basically jumps over if block of code and goes to else block who then activate die function. Can someone explain what and where I did wrong? Thanks a lot!
// This version of code works!
// Check for errors
if(!empty($data['error_blog_title']) && !empty($data['error_blog_body'])){
// There are errors
$this->loadView('blog/edit', $data);
} else{
// No errors, update post
$this->blogModel->updatePost($data);
redirect('/blog/index');
}
VS
// This one doesnt
// Check for errors
if(!empty($data['error_blog_title']) && !empty($data['error_blog_body'])){
// There are errors
$this->loadView('blog/edit', $data);
} else{
if($this->blogModel->updatePost($data)){
// Updated succesfully
redirect('blog/index');
} else{
// Update failed
die('Something went wrong!');
}
}
Aucun commentaire:
Enregistrer un commentaire