CakePHP のベスト プラクティスについて質問があります。
次の状況を想像してみましょう。
領収書モデルには、次のコードがあります。
public function beforeValidate()
{
$this->data[$this->name]["client_id"] = CakeSession::read("Auth.User.id");
$this->data[$this->name]["date"] = date('Y-m-d H:i:s');
$receipt = $this->data[$this->name]["receipt"];
$cod_filial = substr($receipt, 0, 3);
$qtdade_cupom = substr($receipt, 12, 2);
$tipo_pagamento = substr($receipt, 14, 1);
$this->data[$this->name]["cod"] = $cod_filial;
$this->data[$this->name]["quantity"] = $qtdade_cupom;
$this->data[$this->name]["payment_type"] = $tipo_pagamento;
$this->data[$this->name]["is_valid"] = null;
return true;
}
変数 $qtdade_cupom、$cod_filial を使用して、有効な数字をチェックするなど、多くの検証を行う必要があります。
計算はどこで行うのですか??
モデル内に次のようなメソッドを作成します
public function checkDigits()
また
これを行うために動作を作成しますか?
また
他の解決策??