Pemrograman 4
STMIK Bandung
Model News
<?php
class News_model extends CI_Model {
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'text' => $this->input->post('text')
);
if ($id == 0) {
SIMPLE CRUD CODE IGNITER
Pemrograman 4
STMIK Bandung
Controller News
<?php
class News extends CI_Controller {
$this->load->view('templates/header', $data);
$this->load->view('news/index', $data);
$this->load->view('templates/footer');
}
if (empty($data['news_item']))
{
show_404();
}
$data['title'] = $data['news_item']['title'];
SIMPLE CRUD CODE IGNITER
Pemrograman 4
STMIK Bandung
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}
}
else
{
$this->news_model->set_news();
$this->load->view('templates/header', $data);
$this->load->view('news/success');
$this->load->view('templates/footer');
}
}
if (empty($id))
{
show_404();
}
$this->load->helper('form');
$this->load->library('form_validation');
}
else
{
$this->news_model->set_news($id);
//$this->load->view('news/success');
redirect( base_url() . 'index.php/news');
}
}
if (empty($id))
{
show_404();
}
$news_item = $this->news_model->get_news_by_id($id);
$this->news_model->delete_news($id);
redirect( base_url() . 'index.php/news');
}
}
View index.php
<tr>
<td><?php echo $news_item['title']; ?></td>
<td><?php echo $news_item['text']; ?></td>
<td>
<a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View</a> |
<a href="<?php echo site_url('news/edit/'.$news_item['id']); ?>">Edit</a> |
<a href="<?php echo site_url('news/delete/'.$news_item['id']); ?>" onClick="return
confirm('Are you sure you want to delete?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
View view.php
<?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];
?>
View create.php
View edit.php
SIMPLE CRUD CODE IGNITER
Pemrograman 4
STMIK Bandung
View success.php