CakePHP, manually checking multiple models

I have a form that creates the next array on presentation (see below). I use this data in my controller to perform several operations, after which I save them separately. (Saving them right away is not an option). I will need to find a way to test each of these models. I already tried:

$this->Model->set($pertinentData);
$this->Model2->set($pertinentData);
if($this->Model->validates() && $this->Model2->validates()){
    //Do whatever
}

This leads to inaccurate results, says that it checks when I see that it is not, and vice versa.

Does anyone have an idea of ​​a viable option? There is no way to create a model without tables where I can define validation rules for these fields, for example:

Order.package_id
User.first_name
etc...

Any idea is appreciated. Below is the array that forms the form. Thank.

Array
(
[Order] => Array
    (
        [id] => 15
        [package_id] => 1743
        [tariff_id] => 5470
        [tarjeta] => 332
        [numero_tarjeta] => 121204045050
        [vencimiento_tarjeta] => 10/20
        [cod_tarjeta] => 170
        [titular_tarjeta] => JESUS CRISTO
        [tarjeta_nacimiento] => 22/04/1988
        [tarjeta_pais] => Argentina
        [tarjeta_provincia] => Buenos Aires
        [tarjeta_ciudad] => Ciudad
        [tarjeta_cp] => 1428
        [tarjeta_calle] => Calle
        [tarjeta_numero] => 1477
        [tarjeta_piso] => 2
    )

[User] => Array
    (
        [id] => 
        [email] => bla8@gmail.com
        [phone] => 1568134449
        [first_name] => Jesus
        [last_name] => Something
        [documento_tipo] => dni
        [dni] => 335556666
        [nacionalidad] => argentino
        [birthdate] => 22/04/2019
    )

[OrdersCompanion] => Array
    (
        [1] => Array
            (
                [first_name] => Chango
                [last_name] => Mas
                [documento_tipo] => dni
                [dni] => 445556666
                [nacionalidad] => argentino
                [birthdate] => 30/02/2010
            )
        [1] => Array
            (
                [first_name] => Chango
                [last_name] => Mas
                [documento_tipo] => dni
                [dni] => 445556666
                [nacionalidad] => argentino
                [birthdate] => 30/02/2010
            )

    )

)
+4
1

, $useTable= false .

public $useTable = false;

, , ( , ). , , $model. , - cakePHP,

public $useModel = false;
$model = ClassRegistry::init('ContactOperation');

, , , .

$model->set($this->request->data);
    if($model->validates()) {
        $this->Session->setFlash(_('Thank you!'));
        // do email sending and possibly redirect
        // elsewhere for now, scrub the form
        // redirect to root '/'.
        unset($this->request->data);
        $this->redirect('/');
    } else {
        $this->Session->setFlash(_('Errors occurred.'));
        // display the form with errors.
    }

+2

All Articles