MIF_E31211879/application/controllers/Pertanyaan.php

87 lines
2.6 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Pertanyaan extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model("ModelPertanyaan");
}
function index()
{
$pertanyaan = $this->ModelPertanyaan->get_data();
$data = array(
'body' => 'Pertanyaan/list',
'pertanyaan' => $pertanyaan
);
$this->load->view('index', $data);
}
public function input()
{
$pertanyaan = $this->ModelPertanyaan->get_data();
$data = array(
'body' => 'Pertanyaan/input',
'form' => 'Pertanyaan/form',
'pertanyaan' => $pertanyaan,
);
$this->load->view('index', $data);
}
public function insert()
{
$data = array(
'pertanyaan' => $this->input->post('pertanyaan'),
);
if ($this->db->insert("pertanyaan", $data)) {
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
redirect(base_url() . "Pertanyaan");
} else {
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
redirect(base_url() . "Pertanyaan");
}
// echo json_encode($data);
}
function edit(){
$id = $this->uri->segment(3);
$pertanyaan = $this->ModelPertanyaan->get_data_edit($id);
$data = array(
'body' => 'Pertanyaan/edit',
'form' => 'Pertanyaan/form',
'pertanyaan' => $pertanyaan,
);
$this->load->view('index', $data);
}
function update()
{
$id = $this->uri->segment(3);
$data = array(
'pertanyaan' => $this->input->post('pertanyaan'),
);
$this->db->where("id_pertanyaan", $id);
if ($this->db->update("pertanyaan", $data)) {
// code...
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
redirect(base_url() . "Pertanyaan");
} else {
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
redirect(base_url() . "Pertanyaan");
}
}
function delete()
{
$id = $this->input->post("id_pertanyaan");
$this->db->where_in("id_pertanyaan", $id);
if ($this->db->delete("pertanyaan")) {
// $this->session->set_flashdata("notif", $this->Notif->berhasil("Berhasil Input Data"));
redirect(base_url() . "Pertanyaan");
// code...
} else {
$this->session->set_flashdata("notif", $this->Notif->gagal("gagal Input Data"));
redirect(base_url() . "Pertanyaan");
}
}
}