I’m wondering what the best practice is when I want to reuse code to query the database (getting rid of delimiters in strings, transforming data in the database). I think the best way is to write a method or function that I can call whenever I need to.
However I don’t want to tamper with the existing framework, and I have a feeling that Cake is designed such that I will never have to do this but, in the case that I do, what is the best practice?
eg. I’d like to create a method that unravels data in the people.tags field. The current data is a string “Student;Teacher;Staff”. I’d like to transform the information then query the database to acquire this array:
student => ‘n’,
teacher => ‘n’,
staff => ‘y’
Then I’ll pass the array into the view for display.
The database frequently stores information like so and I prefer to avoid repetitive code. What is the best practice? Where should I store the method/function? (It seems that I can’t include files either )
Please feel free to throw references at me,