Welcome Guest, Not a member yet? Register   Sign In
Best Place to Create a Table in MVC

A general question for you all. In an application, I am outputting the result of a query in a table in the view. Right now, the query results are passed to the view via $data and then iterated through rendering the table.

My question is this. Would it be better to build the table in my model, and then just pass the completed table as a string to the view? So I send a string containing the html table code in $data instead of the result array. What is the best approach for MVC?


Mike W.

I think it would be messy to build the table in your model. Personally I'm a big fan of keeping things simple, and this seems like it would just make things complicated. You can do it that way if you want, but I would advise against it. In a few months you are going to look at your code again and gouge your eyeballs out trying to decipher all kinds of " and ' mixed with table rows and columns.

@michael Williams
According to MVC approach, showing any view page is decided by Controller. It's not the job of any MODEL. So, what you are saying is not standard MVC way of working.

I'd say do it in the view, since tables are presentational layouts. If you build your table cleanly (perhaps even using the HTML table class), it should be relatively compact and easy to read. Too, it'll fit in nicely with whatever else you're showing on the page.

Theme © iAndrew 2016 - Forum software by © MyBB