Hi all,
I've just read this part of the doc regarding sql injections (https://docs.phalcon.io/en/latest/reference/models.html#avoiding-sql-injections), and that's really nice to have the models sanitizing the data automatically.
Pronlem is, I'm generating automatically my models and metaData base on my db structure, and I haven't seen any way to "cast" or define the field size as it's done here:
$sth->bindParam(':productTypesId', $productTypesId, PDO::PARAM_INT);
$sth->bindParam(':name', $name, PDO::PARAM_STR, 70);
$sth->bindParam(':price', doubleval($price));
$sth->bindParam(':active', $active, PDO::PARAM_STR, 1);
for reference, here is my xcurrent version of the metaData:
public function metaData()
{
return array (
Meta::MODELS_ATTRIBUTES =>
array (
0 => 'clientpk',
1 => 'account_managerfk',
2 => 'primary_contactfk',
3 => 'company_name',
4 => 'credit',
5 => 'note',
6 => 'firstname',
7 => 'lastname',
8 => 'email',
9 => 'phone',
10 => 'phone2',
11 => 'date_created',
12 => 'date_updated',
13 => 'created_by',
14 => 'updated_by'
),
Meta::MODELS_DATA_TYPES =>
array (
'clientpk' => Col::TYPE_INTEGER,
'account_managerfk' => Col::TYPE_INTEGER,
'primary_contactfk' => Col::TYPE_INTEGER,
'company_name' => Col::TYPE_VARCHAR,
'credit' => Col::TYPE_INTEGER,
'note' => Col::TYPE_VARCHAR,
'firstname' => Col::TYPE_VARCHAR,
'lastname' => Col::TYPE_VARCHAR,
'email' => Col::TYPE_VARCHAR,
'phone' => Col::TYPE_VARCHAR,
'phone2' => Col::TYPE_VARCHAR,
'date_created' => Col::TYPE_DATETIME,
'date_updated' => Col::TYPE_DATETIME,
'created_by' => Col::TYPE_INTEGER,
'updated_by' => Col::TYPE_INTEGER
),
Meta::MODELS_DATA_TYPES_NUMERIC =>
array (
'clientpk' => true,
'account_managerfk' => true,
'primary_contactfk' => true,
'credit' => true,
'created_by' => true,
'updated_by' => true
),
Meta::MODELS_DATA_TYPES_BIND =>
array (
'clientpk' => Col::BIND_PARAM_INT,
'account_managerfk' => Col::BIND_PARAM_INT,
'primary_contactfk' => Col::BIND_PARAM_INT,
'company_name' => Col::BIND_PARAM_STR,
'credit' => Col::BIND_PARAM_INT,
'note' => Col::BIND_PARAM_STR,
'firstname' => Col::BIND_PARAM_STR,
'lastname' => Col::BIND_PARAM_STR,
'email' => Col::BIND_PARAM_STR,
'phone' => Col::BIND_PARAM_STR,
'phone2' => Col::BIND_PARAM_STR,
'date_created' => Col::BIND_PARAM_STR,
'date_updated' => Col::BIND_PARAM_STR,
'created_by' => Col::BIND_PARAM_INT,
'updated_by' => Col::BIND_PARAM_INT
),
Meta::MODELS_PRIMARY_KEY =>
array (
0 => 'clientpk'
),
Meta::MODELS_IDENTITY_COLUMN => 'clientpk',
Meta::MODELS_AUTOMATIC_DEFAULT_INSERT => array(),
Meta::MODELS_AUTOMATIC_DEFAULT_UPDATE => array(),
Meta::MODELS_DEFAULT_VALUES => array(),
Meta::MODELS_EMPTY_STRING_VALUES => array(),
Meta::MODELS_NON_PRIMARY_KEY =>
array (
0 => 'account_managerfk',
1 => 'primary_contactfk',
2 => 'company_name',
3 => 'credit',
4 => 'note',
5 => 'firstname',
6 => 'lastname',
7 => 'email',
8 => 'phone',
9 => 'phone2',
10 => 'date_created',
11 => 'date_updated',
12 => 'created_by',
13 => 'updated_by'
),
Meta::MODELS_NOT_NULL =>
array (
0 => 'company_name',
1 => 'credit',
2 => 'firstname',
3 => 'lastname',
4 => 'email'
));
}
Could anyone let me know how to integrate size/length controls and casting to my models. Thanks.