Cara menambahkan modul baru pada Web Kampus :
Pertama buat dulu table di database, misalnya :
CREATE TABLE `banner` (
`id_banner` int(5) NOT NULL,
`judul` varchar(100) COLLATE latin1_general_ci NOT NULL,
`url` varchar(100) COLLATE latin1_general_ci NOT NULL,
`gambar` varchar(100) COLLATE latin1_general_ci NOT NULL,
`tgl_posting` date NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
ALTER TABLE `banner` ADD PRIMARY KEY (`id_banner`);
Selanjutnya tambahkan pada controller Administrator.php :
<?php
function banner(){
$data['record'] = $this->model_app->view_ordering('banner','id_banner','DESC');
$this->template->load('administrator/template','administrator/mod_banner/view_banner',$data); // Buka di File view_banner.php
}
function tambah_banner(){
if (isset($_POST['submit'])){ $config['upload_path'] = 'asset/banner/'; // Simpan Gambar pada folder asset/banner
$config['allowed_types'] = 'gif|jpg|png|JPG|JPEG|swf'; // Tipe gambar yang di izinkan
$config['max_size'] = '3000'; // File Size gambar dalam KiloByte
$this->load->library('upload', $config);
$this->upload->do_upload('gambar');
$hasil=$this->upload->data();
if ($hasil['file_name']==''){
$data = array('judul'=>$this->input->post('judul'), 'url'=>$this->input->post('url'),
'tgl_posting'=>date('Y-m-d')); }else{
$data = array('judul'=>$this->input->post('judul'), 'url'=>$this->input->post('url'),
'gambar'=>$hasil['file_name'],
'tgl_posting'=>date('Y-m-d')); }
$this->model_app->insert('banner',$data);
redirect('administrator/banner');
}else{
$this->template->load('administrator/template','administrator/mod_banner/view_banner_tambah'); // Buka di File view_banner_tambah.php
}
}
function edit_banner(){
$id = $this->uri->segment(3);
if (isset($_POST['submit'])){ $config['upload_path'] = 'asset/banner/'; // Simpan Gambar pada folder asset/banner
$config['allowed_types'] = 'gif|jpg|png|JPG|JPEG|swf'; // Tipe gambar yang di izinkan
$config['max_size'] = '3000'; // File Size gambar dalam KiloByte
$this->load->library('upload', $config);
$this->upload->do_upload('gambar');
$hasil=$this->upload->data();
if ($hasil['file_name']==''){
$data = array('judul'=>$this->input->post('judul'), 'url'=>$this->input->post('url'));
}else{
$data = array('judul'=>$this->input->post('a'), 'url'=>$this->input->post('b'),
'gambar'=>$hasil['file_name']);
}
$where = array('id_banner' => $this->input->post('id')); $this->model_app->update('banner', $data, $where);
redirect('administrator/banner');
}else{
$proses = $this->model_app->edit('banner', array('id_banner' => $id))->row_array(); $data = array('rows' => $proses); $this->template->load('administrator/template','administrator/mod_banner/view_banner_edit',$data); // Buka di File view_banner_edit.php
}
}
function delete_banner(){
$id = array('id_banner' => $this->uri->segment(3)); $this->model_app->delete('banner',$id);
redirect('administrator/banner');
}
?>
Untuk Models tidak perlu ditambahkan lagi pada web Kampus dan Swarakalibata, karena kita sudah membuat model dinamis, jadi bisa digunakan untuk keperluan proses CRUD, hanya tinggal panggil saja dari Model_app.php seperti yang bisa kita lihat di atas.
Terakhir buat views untuk menampilkan data banner, tambah, edit dan delete data.
buat folder baru pada "Application/views/administrator/mod_banner/"
buat file menampilkan data : "Application/views/administrator/mod_banner/view_banner.php"
buat file menampilkan data : "Application/views/administrator/mod_banner/view_banner_tambah.php"
buat file menampilkan data : "Application/views/administrator/mod_banner/view_banner_edit.php"
Karena kita menggunakan AdminLTE, maka struktur masing2 file di atas sama persis dengan file-file yang sudah ada pada CMS swarakalibata Ci directory "Application/views/administrator/mod_iklansidebar", berikut saya lampirkan file2 untuk views banner.
Semoga berhasil,. :)