首页 > 解决方案 > 如何将数据插入两个不关联的表中 cakephp

问题描述

嗨如何在其他文件控制器的表中插入固定数据,例如我有添加功能来向表“订单”添加新订单,我想在添加新订单时同时,一个固定的数据被添加到我的另一个名为 Actions 的表中,例如表操作包含 ID、ID_User、ACTION、DATE、IP 并且我想添加用户 ID,ACTION 由我固定,如“ADD”或“ UPDATE' 或 'DELETE'....在 cakephp 中是可能的吗?我用过这个,但它不起作用

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');
        }
    } 
}

标签: cakephpcakephp-3.0cakephp-2.0cakephp-2.3cakephp-2.1

解决方案


推荐阅读