(09-24-2015, 07:20 AM)kilishan Wrote: In my view, the controller collects the data and passes it to the view. It's up to the view how to format and display it. And that frequently requires format-related functions.
Separating logic from views is not always convenient but it does provide value long term. Complex SQL queries are faster as a single recordset which often requires PHP loops to process a flat array and turn it into a nested array. You can do formatting at the same time so you aren't adding a lot of overhead by pre-processing. IMO views are presentation only and should compile from raw JSON. Using views in this nature allows you to swap to virtually any templating language with minimal effort. You have better separation of logic in your application (traditional MVC). You can create two way data binds by passing JSON back and forth instead of compiled HTML. You can do client side templating to reduce bandwidth. Some of the newer frameworks are moving in this direction with web components.
(09-24-2015, 07:29 AM)mwhitney Wrote: While this is an ideal which one should look to attain in their views, at some point someone has to look around and realize that some views must do one or the other, or you have to back-door the situation by using a template language which allows you to specify logic (and sometimes function calls) without technically including it directly in the view.
It requires more work and planning up front but I feel the benefits are worth it.
(09-24-2015, 07:29 AM)mwhitney Wrote: How exactly does one accomplish even a simple list without logic or function calls in their view? At some point you're going to need at least a loop.
You will yes. Do you use an ORM? I don't so more often than not I'm looping my query results anyway.