Welcome Guest, Not a member yet? Register   Sign In
Transaction
#1

HI sorry for english, in my controller i control if a record is a user's record before delete the record   :

PHP Code:
  function delete_device($id_record){

    //controllo device di utente
    if(!$this->device_model->control_record_of_user($id_record,$_SESSION['user_id'])){

      $data['messaggi_errore'] = lang('record_non_di_user');

      $data ['redirect'] =base_url().'index.php/device/list_device';

      $this->load->view('templates/header_client',$data );
      $this->load->view('templates/menu_client',$data );

      $this->load->view('common/messaggi_errore',$data );

      $this->load->view('templates/footer_client' ,$data);



    }else{

      $res=$this->device_model
                
->deleteDevice_plus_rimuovi_dispositivi($id_record);


     if($res){

      $data['messaggi_ok'] = lang('inv_record_eliminato');

      $data ['redirect'] =base_url().'index.php/device/list_device';

               $this->load->view('templates/header_client' ,$data);
               $this->load->view('templates/menu_client' ,$data);
               $this->load->view('common/messaggi_ok_no_time'$data);
               $this->load->view('templates/footer_client' ,$data);

      }else{

        $data['messaggi_errore'] = lang('inv_problemi_eliminazione_record');

        $data ['redirect'] =base_url().'index.php/device/list_device';

        $this->load->view('templates/header_client',$data );
        $this->load->view('templates/menu_client',$data );

        $this->load->view('common/messaggi_errore',$data );

        $this->load->view('templates/footer_client' ,$data);


      }

    }

  

this is the fuction to control if record is is a user's record :

PHP Code:
  function control_record_of_user($id_record,$user_id){


    $device $this->get_Device($id_record) ;//get record


    if($device->id_user==$user_id){

      return TRUE;

    }else{

      return FALSE;

    }





  



in my model i have a transaction  in deleteDevice_plus_rimuovi_dispositivi:

PHP Code:
function deleteDevice_plus_rimuovi_dispositivi($record){

      $this->load->model('dev_type_a_model');
      $this->load->model('dev_type_b_model');
      $this->load->model('dev_type_c_model');

      $this->db->trans_start();

      //RIMUOVO I type_a
      $this->dev_type_a_model->rimuovi_type_a_in_uso($record);
      
      
//RIMUOVO I type_b 
      $this->dev_type_b_model->rimuovi_type_b_in_uso($record);

      //RIMUOVO I type_c 
      $this->dev_type_c_model->rimuovi_type_c_in_uso($record);
      
      
//cancello il device
      $this->deleteDevice($record);



      $this->db->trans_complete();

      if ($this->db->trans_status() !== FALSE)
      {
        return TRUE;

      }else{

        return FALSE;

      }

    


With transaction i have an error as the controller control many time if the record is a user's record :
PHP Code:
<h4>A PHP Error was encountered</h4>

<
p>SeverityNotice</p>
<
p>Message:  Trying to get property of non-object</p>
<
p>Filenamemodels/Device_model.php</p>
<
p>Line Number658</p

This is line number 658     if($device->id_user==$user_id){

The process work fine (but i see the error  for  half of second)


if i delete only the record without transaction
 ( deleteDevice($record )   )
 
i haven't error . Why ?
Reply


Messages In This Thread
Transaction - by pippuccio76 - 04-26-2020, 09:17 AM
RE: Transaction - by neuron - 04-26-2020, 09:52 AM
RE: Transaction - by pippuccio76 - 04-26-2020, 10:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB