Postingan lainnya
Foreach error
Ini codingnya
userlist.php
contoh gambar userlist
Foreach masih bisa
Tapi saat saya klik edit muncul kyk gini
itu knp ya kok bisa gitu? Padahal di userlist variabel usernya bisa, tpi pas klik edit malah variabel user tidak terdefinisi, Mohon bantuannya
6 Jawaban:
isi dari id_user nya ada ga gan? coba di die dump deh.., terus itu kenapa ga ter highlight,, bisa jadi masalah qoute nya gan..
@reihanagamsk
ada isinya, soalnya di delete id nya masih bisa, tapi saat klik edit malah error, di die dump masih gk bisa, apa nya yg gk terhighlight?
hmm,, brrti bkn karena qoute, kirain saya yg terhighlight <pre> '' . $row->id_user </pre> disini,, mslhnya ga ke render semestinya, brrti klo di delete bisa bkn disitiu mslhmya.. coba di cek controller atau pass ngoper data ke bagian hlmn edit gan,, mungkin agan lupa passing data variable $user nya..
controller edit sama delete
function edit
<pre> public function edit($id = null) { if ($this->input->post('submit')) {
$this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required|min_length[5]');
$this-&gt;form_validation-&gt;set_rules('level', 'Level', 'required|in_list[admin,member]');
$this-&gt;form_validation-&gt;set_message('required', '%s tidak boleh kosong!');
$this-&gt;form_validation-&gt;set_message('min_length', '%s minimal %d karakter!');
if ($this-&gt;form_validation-&gt;run() === TRUE) {
$data = array(
'password' =&gt; password_hash($this-&gt;input-&gt;post('password'), PASSWORD_DEFAULT),
'level' =&gt; $this-&gt;input-&gt;post('level'),
);
$query = $this-&gt;User_model-&gt;update($id, $data);
if ($query) $message = array('status' =&gt; true, 'message' =&gt; 'Berhasil memperbarui user');
else $message = array('status' =&gt; true, 'message' =&gt; 'Gagal memperbarui user');
$this-&gt;session-&gt;set_flashdata('message', $message);
redirect('user/edit/'.$id, 'refresh');
}
}
$user = $this-&gt;User_model-&gt;get_where(array('id_user' =&gt; $id))-&gt;row();
if (!$user) show_404();
$data['pageTitle'] = 'Edit Data User';
$data['username'] = $user;
$data['pageContent'] = $this-&gt;load-&gt;view('user/useredit', $data, TRUE);
$this-&gt;load-&gt;view('user/userlist', $data);
} </pre>
function hapus
<pre> public function delete($id) { $user = $this->User_model->get_where(array('id_user' => $id))->row();
if (!$user) show_404();
$query = $this-&gt;User_model-&gt;delete($id);
if ($query) $message = array('status' =&gt; true, 'message' =&gt; 'Berhasil menghapus user');
else $message = array('status' =&gt; true, 'message' =&gt; 'Gagal menghapus user');
$this-&gt;session-&gt;set_flashdata('message', $message);
redirect('user', 'refresh');
} } </pre>
apanya yg salah? bengung gue, padahal di function edit sudah ada <pre> $user = $this->User_model->get_where(array('id_user' => $id))->row(); </pre>