Postingan lainnya
Masalah The action you have requested is not allowed. pada Codeigniter
Gini gan.. Saya udah berhasil Read pada CRUD. Pas saya coba Create nya nggak bisa dan malah muncul The action you have requested is not allowed. Minta tolong bener ini gan. Ini codenya
user_model.php (ini model)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_model extends CI_Model {
//load database
public function __construct()
{
parent::__construct();
$this->load->database();
}
//listing user
public function listing()
{
$this->db->select('*');
$this->db->from('artikel');
$query = $this->db->get();
return $query->result();
}
//Fungsi Tambah dan validasinya
public function validation($mode){
$this->load->library('form_validation'); //meload library validation untuk prses memvalidasi
if($mode == 'save')
$this->form_validation->set_rules('judul_artikel','judul_artikel','required|max_lenght[255]');
$this->form_validation->set_rules('isi_artikel','isi_artikel','required|max_lenght[2500]');
$this->form_validation->set_rules('jenis_artikel','jenis_artikel','required|max_lenght[20]');
$this->form_validation->set_rules('keywords','keywords','required|max_lenght[700]');
if($this->form_validation->run())
return TRUE;
else
return FALSE;
}
public function save(){
$data = array(
'judul_artikel' => $this->input->post('judul_artikel'),
'isi_artikel' => $this->input->post('isi_artikel'),
'status_artikel' => $this->input->post('status_artikel'),
'jenis_artikel' => $this->input->post('jenis_artikel'),
'keywords' => $this->input->post('keywords')
);
$this->db->insert('artikel', $data); // Untuk mengeksekusi perintah insert data
}
Du.php(Ini file controller)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Du extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('user_model');
}
public function index()
{
$user = $this->user_model->listing();
$data = array('title' => 'Artikel ('.count($user).')',
'user' => $user,
'isi' => 'u/du/list'
);
$this->load->view('layout/wrapper',$data,FALSE);
}
public function view(){
return $this->db->get('artikel')->result();
}
public function post(){
$data = array('title' => 'Artikel',
'isi' => 'u/du/post'
);
$this->load->view('layout/wrapper',$data,FALSE);
}
public function tambah(){
if($this->input->post('submit')){ // Jika user mengklik tombol submit yang ada di form
if($this->user_model->validation("save")){ // Jika validasi sukses atau hasil validasi adalah TRUE
$this->user_model->save(); // Panggil fungsi save() yang ada di SiswaModel.php
redirect('u/du');
}
}
}
}
post.php(ini file views)
<form method="post">
<div class="form-group">
<label>Judul</label>
<input class="form-control" type="text" name="judul_artikel" value="<?php echo set_value('judul_artikel'); ?>" required>
</div>
<div class="form-group">
<label>Artikel</label>
<input class="form-control" type="text" name="isi_artikel" value="<?php echo set_value('isi_artikel'); ?>" required>
</div>
<div class="form-group">
<label>Status</label>
<input class="form-control" type="text" name="status_artikel" value="<?php echo set_value('status_artikel'); ?>" required>
</div>
<div class="form-group">
<label>Jenis</label>
<input class="form-control" type="text" name="status_artikel" value="<?php echo set_value('jenis_artikel'); ?>" required>
</div>
<div class="form-group">
<label class="">
Keywords
</label>
<div class="form-control">
<textarea name="keywords" class="form-control" value="<?php echo set_value('keywords'); ?>" required></textarea>
</div>
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="Simpan">
</div>
</form>
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban