gpt4 book ai didi

cakephp - 在单个表单中验证多个模型

转载 作者:行者123 更新时间:2023-12-05 01:11:36 26 4
gpt4 key购买 nike

我必须使用“CakePHP”以单一形式验证多个模型。我有 2 个模型。

发票

public $validate = array(
'type' => array(
'rule' =>'notEmpty',
'message' => 'Select Invoice Type.',
'required' => true
),
'number' => array(
'rule' =>'numeric',
'message' => 'Enter Invoice Number.',
'required' => true
),
'date' => array(
'rule' => array('date', 'dmy'),
'allowEmpty' => true,
'message' => 'Enter Invoice Date.'
),
);

public $belongsTo = array(
'Client' => array(
'className' => 'Client',
'foreignKey' => 'client_id'
));

客户端

public $validate = array(
'name' => array(
'rule' =>'notEmpty',
'message' => 'Enter Your Name.',
'required' => true
),
'company' => array(
'rule' =>'notEmpty',
'message' => 'Enter Your Company Name.',
'required' => true
),
'address' => array(
'rule' =>'notEmpty',
'message' => 'Enter Your address.',
'required' => true
)
);

public $hasMany = 'Invoice';

我有一个表单,其中包含“clientName”、“Address”、“InvoiceNumber”和“InvoiceDate<”等字段/em>'。我使用了 saveAll(),但它只验证 Invoice 数据而不是 Client 数据。

最佳答案

看看下面的答案:https://stackoverflow.com/a/4673403/1110760

hasMany model's fields should be as array (when combined with parent model), see .0 added between field names

如果您在遇到问题时也想发布您的表单,我们可以帮助您。

关于cakephp - 在单个表单中验证多个模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14562549/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com