Langkah
Pertama Bikin Table di database yang uda dibuat yaitu DATABASE d4b6 dan kita
buat TABLE news.
CREATE TABLE `db_d4b6`.`news` (`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NOT NULL ,
`create` DATETIME NOT NULL ,
`udpate` DATETIME NOT NULL ,
`delete` DATETIME NOT NULL
`title` VARCHAR( 255 ) NOT NULL ,
`create` DATETIME NOT NULL ,
`udpate` DATETIME NOT NULL ,
`delete` DATETIME NOT NULL
) ENGINE = INNODB;
Insert
isi field-field yang ada di TABLE news pada phpmyadmin. Seperti gambar dibawah.
isi pada
MODEL : NEWS
class Modelnews extends CI_Model {
function __construct()
{
parent::__construct();
}
function getAllNews(){
$q="SELECT * FROM news";
return $this->db->query($q);
}
function deleteById($id){
$q= "DELETE FROM news WHERE id='$id'";
return $this->db->query($q);
}
}
?>
Pada location
/application/config/autoload.php
Pada CONTROLLER : NEWS isikan perintah berikut :
class News extends CI_Controller {
public function index()
{
$data = array ('title' => 'Test Title',
'heading' => 'Test Heading',
'message' => 'Test Message');
$this->load->view('news/view_header');
$this->load->view('news/view_news_show',$data);
$this->load->view('news/view_footer');
}
public function show(){
$data['n'] = $this->Modelnews->getAllNews();
$this->load->view('news/view_show_page', $data);
}
public function delete($id=""){
$this->Modelnews->deleteById($id);
redirect('news/show');
}
public function input() {
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'title', 'required|min_length[5]|max_length[12]|');
$this->form_validation->set_rules('content', 'content', 'required|matches[passconf]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('news/myform');
}
else
{
$this->load->view('formsuccess');
echo "berhasil";
}
}
}
Hasil Tugas CI koneksi ke
DATABASE d4b6 TABLE news (Rezza)
0 comments:
Post a Comment