cakephp - 如何将数据插入两个不关联的表中 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');
}
}
}
解决方案
推荐阅读
- windows - 无法通过 SSH 连接到 Azure Windows Server VM
- python - 谁在他们的公司中使用 pyenv?
- python - 如何在 Python 中绘制 Google QuickDraw 数据集?
- c# - 如何在仅数字排序的字母数字中使用顺序
- powershell - 使用 powershell 在 powerpoint 中编辑形状
- android - 为什么在 Android 中为 NumberPicker 设置 textcolor 时会发生 NoSuchFieldException?
- azure-logic-apps - 如何检索多个逻辑应用程序的“已完成运行”计数
- php - ~/.composer/vendor/laravel/valet/server.php 中的权限被拒绝
- ruby-on-rails - 无法将 project_id 设置为嵌套路由中的数据库
- php - 无法使用 curl 或 file_get_contents 在单独的网站上执行命令