How to insert data into two table not associated cakephp

74 views Asked by At

hi how to insert a fixed data in a table in an other file controller, for example i have the add function to add a new order to table ' order', i would like to , when the new order is added, at the same time, a fixed data is added to my other table called Actions, for example table actions contain ID,ID_User,ACTION,DATE,IP and i would like to add the user ID , the ACTION is fixed by my , like 'ADD' or 'UPDATE' or 'DELETE'.... is that possible in cakephp. i used this but it doesnt work

public function add() {
    if ($this->request->is(array('post'))) {

        $data = $this->request->data;
        $this->loadModel('Historique');
        $article = $this->Historique->newEntity();

        $article->IDUSER = '7';
        $article->ACTIONS = ' article';
        $article->OBJET= 'me';
        $article->IP = ' article';
        $article->DATE = '2020-2-4 04:08:54';


        // die(debug($data));
        if ($this->Role->save($data) and $this->Historique->save($article)) {
            $this->Session->setFlash('Role enregistré avec succès.', 'flash_success');
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash('Rôle n’a pas pu être enregistré. champ vide ou le nom saisi n\'est pas unique, Veuillez réessayer.', 'flash_error');
        }
    } 
}
0

There are 0 answers