Validate field in model without table (CakePHP)

I have a model in CakePHP that does not have a table called Upload. I have a check in this model for a field named source_id.

I have a form that creates beautiful $ this data, giving me a well-formed set, including:

$this->data['Upload']['source_id']

However, the validation rule that I set does not seem to work at all. I copied this validation rule from another model where it works, so I'm sure it works:

var $validate = array(
        'source_id' => array(
        rule' => 'numeric',
        'required' => true,
        'allowEmpty' => false,
        'message' => 'Error!.'
    )
);

Is it possible to check the fields for a model that does not have a database table?

The form uses a load model and passes a different controller action method.

CakePHP 1.2, PHP / MySQL 5, XAMPP.

+3
source share
2 answers

. , save()

$this->Upload->set($this->data);
$this->Upload->validates();

.

+10

, $_schema, :

var $useTable = false;

var $_schema = array(
    'name'   =>array('type'=>'string', 'length'=>100), 
    'email' =>array('type'=>'string', 'length'=>255), 
    'phone' =>array('type'=>'string', 'length'=>20),
    'subject'  =>array('type'=>'string', 'length'=>255),
    'message'  =>array('type'=>'text')
);
+4

Source: https://habr.com/ru/post/1698304/


All Articles