Message: trying to get property 'id_pegawai' of non-object (edit delete ga bisa)

mohon bantuannya master, dari kemarin ga ketemu juga solusinya. tambah data dan hapus semua data itu bisa. tapi kalo edit sama delete itu ga bisa

ini controllernya

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Pegawai extends CI_Controller {

	public function index()
	{
		$this->load->model('nilai/model_pegawai');
		$data['tabelpegawai'] = $this->model_pegawai->getdata();
		$data['content'] = 'view_pegawai';
		$this->load->view('admin/nilai/template_admin', $data);
	}

	public function save()
	{
		$data = array(
			'nipeg'=>$this->input->post('nipeg'),
			'nama'=>$this->input->post('nama'),
			'grade'=>$this->input->post('grade'),
			'jabatan'=>$this->input->post('jabatan'),
			'unit'=>$this->input->post('unit'),
			);
		$this->load->model('nilai/model_pegawai');
		$this->model_pegawai->insertdata($data);

		redirect(site_url('admin/nilai/pegawai'));
	}

	public function delete()
	{
		$id = $this->uri->segment(4);
		$this->load->model('nilai/model_pegawai');
		$this->model_pegawai->deletedata($id);
		$this->load->model('nilai/model_bobot');
		$this->model_bobot->deletedata($id);
		redirect(site_url('admin/nilai/pegawai'));
	}

	public function deleteall()
	{
		$id = $this->uri->segment(4);
		$this->load->model('nilai/model_pegawai');
		$this->model_pegawai->deletedataall();

		redirect(site_url('admin/nilai/pegawai'));
	}

	public function edit()
	{
		$id = $this->uri->segment(4);
		$this->load->model('nilai/model_pegawai');
		$data['rowpegawai'] = $this->model_pegawai->selectdata($id);
		$this->load->view('admin/nilai/view_edit_pegawai', $data);
	}

	public function update()
	{
		$id = $this->uri->segment(4);
		$data = array(
			'nipeg'=>$this->input->post('nipeg'),
			'nama'=>$this->input->post('nama'),
			'grade'=>$this->input->post('grade'),
			'jabatan'=>$this->input->post('jabatan'),
			'unit'=>$this->input->post('unit')
			);
		$this->load->model('nilai/model_pegawai');
		$this->model_pegawai->updatedata($data, $id);
		redirect(site_url('admin/nilai/pegawai'));
	}
}

ini modelnya

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Model_pegawai extends CI_Model {

	public function getdata()
	{
		return $this->db->get('nilaipegawai')->result();
	}

	public function insertdata($data)
	{
		return $this->db->insert('nilaipegawai', $data);
	}

	public function deletedata($id)
	{
		$this->db->where('id_pegawai', $id);
		return $this->db->delete('nilaipegawai');
	}

	public function deletedataall()
	{
		$this->db->from('nilaipegawai');
		$this->db->truncate();
	}

	public function selectdata($id)
	{
		$this->db->where('id_pegawai', $id);
		return $this->db->get('nilaipegawai')->row();
	}

	public function updatedata($data, $id)
	{
		$this->db->where('id_pegawai', $id);
		return $this->db->update('nilaipegawai', $data);
	}

}

ini view nya

<div class="section-isi">
		<div class="container">
			<h3>Data Pegawai</h3>
			<div class="alert alert-info">
				<b>Admin / Data Pegawai</b>
			</div>
		</div>
		<div class="container">

			<div id="accordion" style="margin-bottom: 20px;">


			    <div class="card">
			      <div class="card-header">
			        <a class="card-link" data-toggle="collapse" href="#collapse2">
			          Minimize
			        </a>

					<button type="submit" class="btn btn-sm btn-info " data-toggle="modal" data-target="#modalForm"><i class="fa fa-edit"></i> <b>Tambah Data Bobot Nilai Pegawai</b></button>

					<a href="" class="btn btn-sm btn-danger" onclick="AreYouSureDeleteAll(event)"><i class="fa fa-close"></i><b> Hapus Semua Data</b></a>
				  </div>
			      <div id="collapse2" class="collapse show" data-parent="#accordion">
			        <div class="card-body">

						<!--h5>Data Kriteria</h5-->
							<div style="overflow-y: auto;">
								<table class="table table-hover table-bordered" id="example">
									<thead>
										<tr>
											<th>No</th>
											<th>NIPEG</th>
											<th>Nama</th>
											<th>Grade</th>
											<th>Jabatan</th>
											<th>Unit</th>
											<th>Aksi</th>
										</tr>
									</thead>
									<tbody>
										<?php
											$i=0;
											foreach ($tabelpegawai as $datapegawai)
											{
												$i++;
										?>
										<tr>
											<td><?php echo $i; ?></td>
											<td><?php echo $datapegawai->nipeg; ?></td>
											<td><?php echo $datapegawai->nama; ?>
											<td><?php echo $datapegawai->grade; ?></td>
											<td><?php echo $datapegawai->jabatan; ?></td>
											<td><?php echo $datapegawai->unit; ?></td>
										</td>
											<td>
												<a data-toggle="modal" class="btn btn-sm btn-warning" data-show="true" href="<?php echo site_url('admin/nilai/pegawai/edit/'.$datapegawai->id_pegawai); ?>" data-target="#myModal<?php echo $datapegawai->id_pegawai; ?>" title="Edit" onclick="showmodal('<?php echo $datapegawai->id_pegawai; ?>');"><i class="fa fa-edit"></i></a>
												 <a href="" class="btn btn-sm btn-danger" onclick="AreYouSure(event, '<?php echo $datapegawai->id_pegawai; ?>');"><i class="fa fa-close"></i></a>
											</td>
										</tr>
										<?php
											}
										?>

									</tbody>
								</table>
								<?php
											$i=0;
											foreach ($tabelpegawai as $datapegawai)
											{
												$i++;
										?>
										<div id="myModal<?php echo $datapegawai->id_pegawai; ?>" class="modal fade" role="dialog">
										  <div class="modal-dialog" role="document">
									<div class="modal-content modal-container" id="container<?php echo $datapegawai->id_pegawai; ?>">
											</div>
										  </div>
										</div>
										<?php
											}
										?>
							</div>

																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																	        </div>
			      </div>
			    </div>


			  </div>

		</div>

	</div>

	<!-- MODAL -->
    <div class="modal fade" id="modalForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header text-center">
                    <h4 class="modal-title w-100 font-weight-bold">Tambah Data pegawai</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
				<form action="<?php echo site_url('admin/nilai/pegawai/save'); ?>" method="post">
                <div class="modal-body">
                      <div class="form-group">
                        <label>NIPEG</label>
                        <input type="text" class="form-control" name="nipeg" placeholder="Masukkan NIPEG Pegawai" required>
                      </div>
                      <div class="form-group">
                        <label>Nama</label>
                        <input type="text" class="form-control" name="nama" placeholder="Masukkan Nama Pegawai" required>
                      </div>

                      <div class="form-group">
                        <label>Grade</label>
                      <select class="form-control" name="grade" placeholder="Pilih Grade" required>
					  <option value="BAS01">BAS01</option>
					  <option value="BAS02">BAS02</option>
					  <option value="OPT01">OPT01</option>
					  <option value="OPT02">OPT02</option>
					  <option value="OPT03">OPT03</option>
					  <option value="OPT04">OPT04</option>
					  <option value="SPE01">SPE01</option>
					  <option value="SPE02">SPE02</option>
					  <option value="SPE03">SPE03</option>
					  <option value="SPE04">SPE04</option>
					  <option value="SYS01">SYS01</option>
					  <option value="SYS02">SYS02</option>
					  <option value="SYS03">SYS03</option>
					  <option value="SYS04">SYS04</option>
					  <option value="ADV01">ADV01</option>
					  <option value="ADV02">ADV02</option>
					</select>
					</div>

                      <div class="form-group">
                        <label>Jabatan</label>
                      <select class="form-control" name="jabatan" placeholder="Pilih Jabatan" required>
					  <option value="Fungsional III">Fungsional III</option>
					  <option value="Fungsional IV">Fungsional IV</option>
					  <option value="Fungsional V">Fungsional V</option>
					  <option value="Fungsional VI">Fungsional VI</option>
					  <option value="Supervisori Dasar">Supervisori Dasar</option>
					  <option value="Supervisori Atas">Supervisori Atas</option>
					  <option value="Manajemen Dasar">Manajemen Dasar</option>
					  <option value="Manajemen Menengah">Manajemen menengah</option>
					  <option value="Manajemen Atas">Manajemen Atas</option>
					</select>
					</div>

                      <div class="form-group">
                        <label>Unit</label>
                        <input type="text" class="form-control" name="unit" placeholder="Masukkan Unit Pegawai" required>
                      </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-sign" id="btn-sign" name="button">Simpan</button>
                </div>
				</form>
            </div>
        </div>
    </div>

	<script type="text/javascript">
    function AreYouSure(event, _id) {
      event.preventDefault();
      swal({
      title: "Konfirmasi",
      text: "Apakah Anda Yakin Ingin Menghapus Data ?",
      icon: "warning",
      closeOnClickOutside: true,
      buttons: [true,"Yes"],
      })
      .then((Yes) => {
      if(Yes){
		document.location='<?php echo site_url('admin/nilai/pegawai/delete'); ?>/'+_id;
		return true;
      } else {
		return false;
	  }
      });
	  return false;
    }
  </script>

<script type="text/javascript">
 function AreYouSureDeleteAll(event) {
      event.preventDefault();
      swal({
      title: "Konfirmasi",
      text: "Apakah Anda Yakin Ingin Menghapus Semua Data ?",
      icon: "warning",
      closeOnClickOutside: true,
      buttons: [true,"Yes"],
      })
      .then((Yes) => {
      if(Yes){
		document.location='<?php echo site_url('admin/nilai/pegawai/deleteall'); ?>';
		return true;
      } else {
		return false;
	  }
      });
	  return false;
    }
  </script>

	<script type="text/javascript">
		function showmodal(_id){
			$('#container'+_id).load("<?php echo site_url('admin/nilai/pegawai/edit'); ?>/"+_id, function(result){
				$('#container'+_id).html(result);
				//$('#myModal'+_id).modal({show:true});
			});
		}
	</script>
<div class="modal-header text-center">
	<h4 class="modal-title w-100 font-weight-bold">Edit Data pegawai</h4>
	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
		<span aria-hidden="true">×</span>
	</button>
</div>
<form action="<?php echo site_url('admin/nilai/pegawai/update/'.$rowpegawai->id_pegawai); ?>" method="post">
<div class="modal-body">
	  <div class="form-group">
    <label>NIPEG</label>
		<input type="text" class="form-control" name="nipeg" placeholder="Masukkan ID pegawai" value="<?php echo $rowpegawai->nipeg; ?>" readonly>
	  </div>
                      <div class="form-group">
                        <label>Nama</label>
                        <input type="text" class="form-control" name="nama" placeholder="Masukan Nama Pegawai" value="<?php echo $rowpegawai->nama; ?>" required >
                      </div>
                      <div class="form-group">
                        <label>Grade</label>
                        <input type="text" class="form-control" name="grade" placeholder="Masukan Grade Pegawai" value="<?php echo $rowpegawai->grade; ?>" required>
                      </div>
                      <div class="form-group">
                        <label>Jabatan</label>
                        <input type="text" class="form-control" name="jabatan" placeholder="Masukan Jabatan Pegawai" value="<?php echo $rowpegawai->jabatan; ?>" required>
                      </div>
                      <div class="form-group">
                        <label>Unit</label>
                        <input type="text" class="form-control" name="unit" placeholder="Masukan Unit Pegawai" value="<?php echo $rowpegawai->unit; ?>" required>
                      </div>
<div class="modal-footer">
	<button type="submit" class="btn btn-sign" id="btn-sign" name="button">Simpan</button>
</div>
</form>

avatar nurard1408
@nurard1408

10 Kontribusi 0 Poin

Diperbarui 4 tahun yang lalu

Tanggapan

coba ss urlnya

2 Jawaban:

Jawaban Terpilih

Coba di ubah jadi seperti ini

<pre> $id = $this-&gt;uri-&gt;segment(5); </pre>

ID nya ada di URL segment ke 5 <pre> site_url('admin/nilai/pegawai/update/'.$rowpegawai-&gt;id_pegawai)

// url: localhost/nama_app/admin/nilai/pegawai/update/4 // segment: 1 2 3 4 5 &lt;- id nya ada di segment 5 </pre>

avatar irmanfrdev
@irmanfrdev

8 Kontribusi 10 Poin

Dipost 4 tahun yang lalu

oke thanks banget bro irmanfrdev work..!!

avatar nurard1408
@nurard1408

10 Kontribusi 0 Poin

Dipost 4 tahun yang lalu

Login untuk ikut Jawaban