我正在使用OctoberCMS构建器插件来创建表单以将数据存储到数据库中 . 默认情况下,每个模型都属于一个数据库表 . 表单可以将数据存储到单个数据库表中 . 那么如何使用Builder插件将数据插入从单个表单中捕获的2个不同的表中 .
问候
为此,您必须使用模型类手动处理保存过程 .
1-打开您的模型类 .
2-写一个模型甚至像 public function afterSave(){} 这样的功能
public function afterSave(){}
例如,如果我在 reservation 模型中有一个 total 字段,我想要将此字段值自动插入另一个名为 accounting 的表中 .
reservation
total
accounting
public function afterSave(){ $accounting = \Namespace\Pluginname\Models\Accounting::find(1); $accounting->myField = $this->total; $accounting->save(); }
因此,在 afterSave , beforeSave , beforeCreate 或 afterCreate 中,您可以处理模型的保存过程 .
afterSave
beforeSave
beforeCreate
afterCreate
要查看这些功能之间的差异,您可以在此链接上阅读更多信息:https://octobercms.com/docs/database/model#events
1 回答
为此,您必须使用模型类手动处理保存过程 .
1-打开您的模型类 .
2-写一个模型甚至像
public function afterSave(){}
这样的功能例如,如果我在
reservation
模型中有一个total
字段,我想要将此字段值自动插入另一个名为accounting
的表中 .因此,在
afterSave
,beforeSave
,beforeCreate
或afterCreate
中,您可以处理模型的保存过程 .要查看这些功能之间的差异,您可以在此链接上阅读更多信息:https://octobercms.com/docs/database/model#events