Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Mahasiswa extends Controller {
- public function __construct()
- {
- if (!isset($_SESSION['login'])) {
- header('Location: '. BASEURL);
- exit;
- }
- }
- public function index()
- {
- $data['title'] = 'Halaman Mahasiswa';
- $data['mhs'] = $this->model('Mahasiswa_model')->getAllMahasiswa();
- $data['jurusan'] = [
- 'Teknik Informatika',
- 'Teknik Industri',
- 'Teknik Pangan',
- 'Teknik Planologi',
- 'Teknik Ligkungan',
- 'Sistem Informasi',
- 'Teknik Mesin'
- ];
- $this->view('_templates/header', $data);
- $this->view('mahasiswa/index', $data);
- $this->view('_templates/footer');
- }
- public function detail($id)
- {
- $data['title'] = 'Halaman Detail Mahasiswa';
- $data['mhs'] = $this->model('Mahasiswa_model')->getMahasiswaById($id);
- $this->view('_templates/header', $data);
- $this->view('mahasiswa/detail', $data);
- $this->view('_templates/footer');
- }
- public function tambah()
- {
- if ($this->model('Mahasiswa_model')->tambahDataMahasiswa($_POST) > 0) {
- Flasher::setFlash('berhasil', 'ditambahkan', 'success');
- header("Location: ". BASEURL ."/mahasiswa");
- exit;
- } else {
- Flasher::setFlash('gagal', 'ditambahkan', 'danger');
- header("Location: ". BASEURL ."/mahasiswa");
- exit;
- }
- }
- public function hapus($id)
- {
- if ($this->model('Mahasiswa_model')->hapusDataMahasiswa($id) > 0) {
- Flasher::setFlash('berhasil', 'dihapus', 'success');
- header('Location: ' . BASEURL . '/mahasiswa');
- exit;
- } else {
- Flasher::setFlash('gagal', 'dihapus', 'danger');
- header('Location: ' . BASEURL . '/mahasiswa');
- exit;
- }
- }
- public function ubah()
- {
- if ($this->model('Mahasiswa_model')->ubahDataMahasiswa($_POST) > 0) {
- Flasher::setFlash('berhasil', 'diubah', 'success');
- header('Location: ' . BASEURL . '/mahasiswa');
- exit;
- } else {
- Flasher::setFlash('gagal', 'diubah', 'danger');
- header('Location: ' . BASEURL . '/mahasiswa');
- exit;
- }
- }
- public function cari()
- {
- $data['title'] = 'Halaman Mahasiswa';
- $data['mhs'] = $this->model('Mahasiswa_model')->cariDataMahasiswa();
- $data['jurusan'] = [
- 'Teknik Informatika',
- 'Teknik Industri',
- 'Teknik Pangan',
- 'Teknik Planologi',
- 'Teknik Ligkungan',
- 'Sistem Informasi',
- 'Teknik Mesin'
- ];
- if (empty($data['mhs'])) {
- echo '<script>
- alert("Nama mahasiswa tidak ditemukan");
- </script>';
- }
- $this->view('_templates/header', $data);
- $this->view('mahasiswa/index', $data);
- $this->view('_templates/footer');
- }
- public function getUbah()
- {
- echo json_encode($this->model('Mahasiswa_model')->getMahasiswaById($_POST["id"]));
- }
- }
Add Comment
Please, Sign In to add comment