我必须使用“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 ”等字段。我使用了 saveAll(),但它只是验证Invoice
数据而不是Client
数据。