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

(04-26-2020, 09:52 AM)neuron Wrote: Error is not CI related, it is a general PHP error.


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

    $device = $this->get_Device($id_record) ;//get record
   
    //here run print_r($device); die(); to check the what is inside of the $device variable.
    // you can update codes below like this: return $device->id_user==$user_id;
    if($device->id_user==$user_id){

      return TRUE;

    }else{

      return FALSE;

    }

  }

In your method you are not checking if the get_Device method returning an object, if there is not record with that $id_record it might return NULL. Or as error says even if it returns something it is type maybe not an object but array. By running print_r($device) check what is inside of it.
Also, I suggest to not run separate method to check if the record belongs to the user. Instead, build your SQL query with the condition for example:

DELETE from records
WHERE record_id = 2 and id_user = 56

Also, you can build DB constraints (Foreign key, DB relations).
For example, you have users and users have records. In DB you can build a constraint saying if a user is deleted then delete its records also.
This way you don't have to run separate queries, and use transactions.


The method :
Code:
    public function get_Device($id_record){

        $this->db->where('id', $id_record);


           $q=$this->db->get('device');

          $res=$q->row();

          return $res;



    }

return object because to delete must push on a button and with jquery i get  the id to delete .
With only deleteDevice($record) (in the model inside a transaction) called in place of deleteDevice_plus_rimuovi_dispositivi($record) not error  are showing .

F
or this I suggest to not run separate method to check if the record belongs to the user. Instead, build your SQL query with the condition for example

I do it to show the right mistake.
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