Where to put a recursive function when following MVC?

Posted by Glibly on Stack Overflow See other posts from Stack Overflow or by Glibly
Published on 2010-06-11T09:41:58Z Indexed on 2010/06/11 9:52 UTC
Read the original article Hit count: 195

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about mvc

Related posts about design-patterns