Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Controllers;
- use CodeIgniter\Controller;
- use App\Models\JurusanModel;
- class Jurusan extends Controller
- {
- public function index()
- {
- $model = new JurusanModel();
- $data['jurusan'] = $model->orderBy('id', 'ASC')->findAll();
- return view('jurusan/index', $data);
- }
- public function tambah()
- {
- $this->session = \Config\Services::session();
- if(!isset($_SESSION['inputs'])){
- $data = array(
- 'jurusan' => '',
- 'kapasitas' => '',
- 'terisi' => ''
- );
- session()->setFlashdata('inputs', $data);
- }
- return view('/jurusan/tambah');
- }
- public function simpan()
- {
- helper(['form', 'url']);
- $validation = \Config\Services::validation();
- $data = array(
- 'jurusan' => $this->request->getPost('jurusan'),
- 'kapasitas' => $this->request->getPost('kapasitas'),
- 'terisi' => $this->request->getPost('terisi')
- );
- if($validation->run($data, 'jurusan')) {
- $model = new JurusanModel();
- $model->insert($data);
- session()->setFlashdata('success', 'Berhasil menyimpan Jurusan ' . $this->request->getPost('jurusan'));
- return redirect()->to(base_url('/jurusan'));
- }else{
- session()->setFlashdata('inputs', $this->request->getPost());
- session()->setFlashdata('errors', $validation->getErrors());
- return redirect()->to(base_url('/jurusan/tambah'));
- }
- }
- public function edit($id)
- {
- $this->session = \Config\Services::session();
- if(!isset($_SESSION['input'])){
- $data = array(
- 'jurusan' => '',
- 'kapasitas' => '',
- 'terisi' => ''
- );
- session()->setFlashdata('input', $data);
- }
- $model = new JurusanModel();
- $data['jurusan'] = $model->where('id', $id)->first();
- return view('/jurusan/edit', $data);
- }
- public function update()
- {
- //helper(['form', 'url']);
- $id = $this->request->getPost('id');
- $validation = \Config\Services::validation();
- $data = array(
- 'jurusan' => $this->request->getPost('jurusan'),
- 'kapasitas' => $this->request->getPost('kapasitas'),
- 'terisi' => $this->request->getPost('terisi')
- );
- if($validation->run($data, 'jurusan')) {
- $model = new JurusanModel();
- $model->update($id, $data);
- session()->setFlashdata('success', 'Berhasil mengupdate Jurusan ' . $this->request->getPost('jurusan'));
- return redirect()->to(base_url('/jurusan'));
- }else{
- session()->setFlashdata('input', $this->request->getPost());
- session()->setFlashdata('errors', $validation->getErrors());
- return redirect()->to(base_url('/jurusan/edit/' . $id));
- }
- }
- public function hapus($id)
- {
- $model = new JurusanModel();
- $model->where('id', $id)->delete();
- session()->setFlashdata('success', 'Berhasil menghapus Jurusan');
- return redirect()->to(base_url('/jurusan'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement