Postingan lainnya
CodeIgniter [Message: Trying to get property 'idbooking' of non-object]
CodeIgniter Tidak bisa menampilkan data berikut code untuk form editdata.php
<body class="bg-dark">
<div class="container">
<div class="card card-register mx-auto mt-5">
<div class="card-header">Update Data Booking</div>
<div class="card-body">
<?php foreach($databooking as $row){ ?>
<form method="POST" action="<?php echo base_url();?>dbooking/update" onsubmit="return cekform();">
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="exampleInputName">Nama Customer</label>
<input type="hidden" name="idbooking" value="<?php echo $row->idbooking ?>">
<input class="form-control" id="namacustomer" type="text" name="namacustomer" aria-describedby="namacustomer" value="<?php echo $row->namacustomer ?>">
</div>
</div>
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="exampleInputBagian">Bagian Pekerjaan</label>
<input class="form-control" id="bagian" type="text" name="bagian" aria-describedby="bagian" value="<?php echo $row->bagian; ?>">
</div>
</div>
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="exampleInputNohp">Nomor Handphone</label>
<input class="form-control" id="nohp" type="text" name="nohp" aria-describedby="nohp" value="<?php echo $row->nohp; ?>">
</div>
</div>
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="exampleInputEmail">Email</label>
<input class="form-control" id="email" type="text" name="email" aria-describedby="email" value="<?php echo $row->email; ?>">
</div>
</div>
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="exampleInputNamaperusahaan">Nama Perusahaan</label>
<input class="form-control" id="nperusahaan" type="text" name="nperusahaan" aria-describedby="nperusahaan" value="<?php echo $row->nperusahaan; ?>">
</div>
</div>
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="exampleAlamat">Alamat</label>
<input class="form-control" id="alamat" type="text" name="alamat" aria-describedby="alamat" value="<?php echo $row->alamat; ?>">
</div>
</div>
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="exampleInputJenislift">Jenis Lift</label>
<select class="form-control" id="jenislift" type="text" name="jenislift" value="<?php echo $row->jenislift; ?>">
<option></option>
<option>Cargo</option>
<option>Dumbwaiter</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="exampleInputJumlahlantai">Jumlah Lantai</label>
<input class="form-control" id="jmllantai" type="text" name="jmllantai" aria-describedby="jmllantai" value="<?php echo $row->jmllantai; ?>">
</div>
</div>
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="exampleInputTanggal">Tanggal</label>
<input class="form-control" id="tanggal" type="date" name="tanggal" aria-describedby="tanggal" value="<?php echo $row->tanggal; ?>">
</div>
</div>
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="exampleInputJenislift">Status</label>
<select class="form-control" id="status" type="text" name="status" value="<?php echo $row->status; ?>">
<option></option>
<option>Pending</option>
<option>Proses</option>
</select>
</div>
</div>
</div>
<br>
<button type="submit" class="btn btn-primary btn-small">simpan</button>
<a href="<?php echo base_url(); ?>dbooking" class="btn btn-primary btn-small">kembali</a>
</form>
<?php } ?>
</div>
</div>
</div>
Code untuk Controller Data :
class Dbooking extends CI_Controller {
public function __construct()
{
parent:: __construct();
$this->auth->cek_login();
$this->load->model(array('m_crud','m_login'));
}
function index()
{
$data['datauser'] = $this->m_login->get_datalogin($this->session->userdata('username'));
$data['dbooking'] = $this->m_crud->getAll('databooking');
$this->template->load('admin/admins','admin/dbooking',$data);
}
function tambah()
{
$data['datauser'] = $this->m_login->get_datalogin($this->session->userdata('username'));
$this->template->load('admin/admins','admin/tdbooking',$data);
}
function simpan()
{
$data['datauser'] = $this->m_login->get_datalogin($this->session->userdata('username'));
$namacustomer = $this->input->post('namacustomer');
$bagian = $this->input->post('bagian');
$nohp = $this->input->post('nohp');
$email = $this->input->post('email');
$nperusahaan = $this->input->post('nperusahaan');
$alamat = $this->input->post('alamat');
$jenislift = $this->input->post('jenislift');
$jmllantai = $this->input->post('jmllantai');
$tanggal = $this->input->post('tanggal');
$data = array(
'namacustomer'=>$namacustomer,
'bagian'=>$bagian,
'nohp'=>$nohp,
'email'=>$email,
'nperusahaan'=>$nperusahaan,
'alamat'=>$alamat,
'jenislift'=>$jenislift,
'jmllantai'=>$jmllantai,
'tanggal'=>$tanggal);
$this->m_crud->insert('databooking',$data);
redirect(base_url('dbooking/tambah'));
}
function edit($id)
{
$data['datauser'] = $this->m_login->get_datalogin($this->session->userdata('username'));
$where = array('idbooking' => $id);
$data['databooking'] = $this->m_crud->edit($where, 'databooking');
$this->template->load('admin/admins','admin/edbooking',$data);
}
function update()
{
$data['datauser'] = $this->m_login->get_datalogin($this->session->userdata('username'));
$idbooking = $this->input->post('idbooking');
$namacustomer = $this->input->post('namacustomer');
$bagian = $this->input->post('bagian');
$nohp = $this->input->post('nohp');
$email = $this->input->post('email');
$nperusahaan = $this->input->post('nperusahaan');
$alamat = $this->input->post('alamat');
$jenislift = $this->input->post('jenislift');
$jmllantai = $this->input->post('jmllantai');
$tanggal = $this->input->post('tanggal');
$status = $this->input->post('status');
$data = array(
'namacustomer'=>$namacustomer,
'bagian'=>$bagian,
'nohp'=>$nohp,
'email'=>$email,
'nperusahaan'=>$nperusahaan,
'alamat'=>$alamat,
'jenislift'=>$jenislift,
'jmllantai'=>$jmllantai,
'tanggal'=>$tanggal,
'status'=>$status);
$where = array('idbooking' => $id);
$this->m_crud->update($where, $data, 'databooking');
redirect(base_url('dbooking/index'));
}
}
berikut code model M_crud :
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class M_crud extends CI_Model {
public function __construct() {
/**
Info : This library was build to help us to make some simple crud
**/
}
public function getAll($table){
return $this->db->get($table)->result();
}
public function getN($table, $kolom, $variabel){
return $this->db->where($kolom, $variabel)
->get($table)->result();
}
public function getByID($table,$pk,$id){
$this->db->where($pk,$id);
return $this->db->get($table);
}
public function insert($table, $data){
$this->db->insert($table, $data);
}
public function edit($where, $table){
return $this->db->where($table, $where);
}
public function update($where, $data, $table){
$this->db->where($where);
$this->db->update($table, $data);
}
public function delete($table, $pk, $id){
$this->db->where($pk, $id)->delete($table);
}
}
permasalahannya adalah A PHP Error was encountered Severity: Notice
Message: Trying to get property 'idbooking' of non-object
Filename: admin/edbooking.php
Line Number: 30
tolong dibantu ya teman-teman
0
2 Jawaban:
itu di model, function editnya tidak mengembalikan hasilnya
contoh untuk mengembalikan hasilnya :
return $this->db->get_where($table, $data)->row();
0
variable yang diforeach di view harusnya $dbooking bukan $databooking
0