Where to put a recursive function when following MVC?
- by Glibly
Hello,
I have a recursive function being used to generate a menu on my site. The function is calling a database for each level of children in the menu, and generating html for them.
I've currently put this function in a Model part of the code, however, I feel that generating html in the model goes against the MVC.
I didn't put it in a Controller because I didn't want to have database calls or HTML generation there.
I didn't put it in a View because I didn't want database calls there either.
Is the 'correct' way of tackling this problem to have a Controller call a recursive function in a Model that returns a 2d array representing the menu. Then pass the array to a view which has it's own recursive function for generating html from the array?