如何使用插入/更新回调codeIgniter

时间:2016-01-25 06:38:57

标签: php codeigniter callback crud grocery-crud

我有3个表,tbl_reservasitbl_ruanganuser

我想将tbl_ruangan.statusTersedia更新为Tidak Tersedia

这是我的控制人员:

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

class Reservation extends MY_Controller {

public function index()
{
    $this->push_breadcrumb('Reservation', 'reservation');
    // CRUD table
    $this->load->helper('crud');
    $crud = generate_crud('tbl_reservasi');
    $crud->set_subject('Reservasi');

    //Label Fields
    $crud->display_as('kdReservasi','Kode Reservasi');
    $crud->display_as('kd','Ruangan');
    $crud->display_as('id','User');
    $crud->display_as('tanggalMasuk','Tanggal Masuk');
    $crud->fields('kd','id','tanggalMasuk');
    $crud->required_fields('kd','id','tanggalMasuk');

    //Kolom Input dan Callbacks       
    $crud->set_relation('kd','tbl_ruangan','{kd} - {kdRuangan} - {jenis} - {namaRuangan}', array('status' => 'Tersedia'));
    $crud->set_relation('id','users','{id} - {email} - {first_name} {last_name}', array('active' => '1'));
    $crud->callback_after_insert(array($this, 'status_update'));

    //Cetak Halaman
    $this->mTitle = "Reservation";
    $this->mViewFile = '_partial/crud';
    $this->mViewData['crud_data'] = $crud->render();
}

function status_update($post_array,$primary_key)
    {
        $_update = array(
            "kd" => $primary_key,
            "status" => 'Tidak Tersedia'
        );
        $this->db->update('tbl_ruangan',$_update, array('kd' => $primary_key));
        return true;
    }

每次我插入数据,插入ruanganusertanggalMasuk时,它都不会直接将status更改为Tidak Tersedia。在插入具有相同值的2条记录后,它会发生变化。

我想要的只是当我从tbl_reservasi插入记录,然后statustbl_ruangan更改为Tidak Tersedia

0 个答案:

没有答案