You can use the Entity for this, through a virtual field.
Leave your field (which is saved in the bank) as Hidden, and create a new field (with another name) as virtual.
Dai, creates a Setter that takes the value in string, transforms it into number and saves the data in the database field, and a getter takes the database number and returns the string.
It would be something like that:
class User extends Entity
{
protected $_hidden = ['permissoes'];
protected $_virtual = ['cargo'];
protected function _getCargo()
{
$dicionario = [
0 => 'admin',
1 => 'vendas',
2 => 'Edição',
3 => 'Financeiro'
];
return $dicionario[$this->_properties['permissoes']];
}
protected function _setCargo($cargo)
{
$dicionario = [
'admin' => 0,
'vendas' => 1,
'Edição' => 2,
'Financeiro' => 3
];
return $dicionario[$cargo];
}
}
I believe that this part of the documentation can help you better, https://book.cakephp.org/3.0/en/views/helpers/form.html#options-for-select-checkbox-and-radio-Controls
– AugustoMorais
Thank you for the answer. So, do you have how to do this on the model, facilitating maintenance afterwards?
– Jean K. Santos