Codeigniter 3 A PHP Error was encountered Severity: Warning Message: Undefined array key "id"
one text
i try to update or edit some data and ive got this error
here's my model
Jurusan_model.php
private $table = "tbl_jurusan";
public $id;
public $jurusan;
public function rules()
{
return [
['field' => 'jurusan',
'label' => 'jurusan',
'rules' => 'required']
];
}
public function update()
{
$post = $this->input->post();
$this->id = $post["id"];
$this->jurusan = $post["jurusan"];
return $this->db->update($this->table, $this, array('id' => $post['id']));
}
and the controller
JurusanController.php
public function __construct()
{
parent::__construct();
$this->load->model('Jurusan_model');
}
public function edit($id = null)
{
if (!isset($id)) redirect('JurusanController');
$jurusan = $this->Jurusan_model;
$validation = $this->form_validation;
$validation->set_rules($jurusan->rules());
if ($validation->run()) {
$jurusan->update();
redirect('JurusanController', $this->session->set_flashdata('success', 'Berhasil diubah'));
}
$data["jurusan"] = $jurusan->getJurusanById($id);
if (!$data["jurusan"]) show_404();
$this->load->view("edit/edit_jurusan", $data);
}
and ive got this error
A PHP Error was encountered
Severity: Warning
Message: Undefined array key "id"
Filename: models/Jurusan_model.php
Line Number: 42
A PHP Error was encountered
Severity: Warning
Message: Undefined array key "id"
Filename: models/Jurusan_model.php
Line Number: 44
well i try
var_dump($jurusan);
at jurusan controller while i try update some data and here the result
Sourceobject(Jurusan_model)#22 (3) { ["table":"Jurusan_model":private]=> string(11) "tbl_jurusan" ["id"]=> NULL ["jurusan"]=> string(10) "Tatabusana" }