In many cases we have data in the database that is not in the format that we want them to be displayed.
As an example, let's say I have a table called users and in this table a field called role that will store a user's access level. Let's say the role value is ADMIN .
When I want to output these data after retrieving them from the database, I do not want the user to see the value of the role field (which in this case is ADMIN ) but I want him to see DIRECTOR . This is a fictitious example to illustrate that there are actually many situations where in the database the stored data is one but the output of it to the user must be another.
My question is: how do you usually treat this at the level of PHP ?
Using the framework CakePHP I'm currently using callback afterFind that takes the current result from the database and creates an extra element in the array with the o index and treat all the output data.
An example. Suppose I got the following array of results from the database:
user_id => 1,
username => 'joao',
role => 'ADMIN'
After going through my callback, the array will be:
user_id => 1,
username => 'joao',
role => 'ADMIN'
o =>
user_id => 1,
username => 'joao',
role => 'DIRETOR'
And at the time of output, ie print in the view, I only use the or index. The rest are for internal use in the controllers.