mardi 10 novembre 2015

check if data exist before saving in cakephp

im quite new to cake3 i don't know if how can manage to do this i have two

table users and accounts

users contain Id,EmployeeId,Password,Logs

accounts contain Id,EmployeeId,Password,Fname,Lname,Role

what i want to happen is before the data is save in users table it will check first if the Employee Id and Password is present in the accounts table how do i do this in cakephp 3?

i have this in one of my controllers

$user = $this->Users->newEntity();
        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->data);
            if ($this->Users->save($user)) {
                $this->Flash->success(__('Log Time Saved!.'));
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__('The user could not be saved. Please, try again.'));
            }
        }
        $this->set(compact('user'));
        $this->set('_serialize', ['user']);

Aucun commentaire:

Enregistrer un commentaire