Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
This has been brought up before, especially in my previous questions, and I've finally implemented it. What is everyones opinion on a function or class dedicated to view? I use the below function within a template, instead of creating an additional template file.
psurrena wrote:This has been brought up before, especially in my previous questions, and I've finally implemented it. What is everyones opinion on a function or class dedicated to view? I use the below function within a template, instead of creating an additional template file.
In my opinion, you should keep all of your html in template files. I'd use a view class when you're applying presentation logic on data (formatting, etc) and/or grabbing info from the database, and then hand that information off to a template file that simply outputs the information in the correct spots.
My main question is whether it is more maintainable to do the same thing using a general Template class/function that loads a PHP template (or some other kind of template). Then you don't have to write custom functions each time.
psurrena wrote:This has been brought up before, especially in my previous questions, and I've finally implemented it. What is everyones opinion on a function or class dedicated to view? I use the below function within a template, instead of creating an additional template file.
What's with all those namespaces? Bad joke, I know
For me this is too much html to have in a function. Everything depends on circumstances of course, but if you have most of it in templates in your template directory, why not put all in it? Actually, to turn the question around: what makes you want to have this html snippet inside a function?
Actually, to turn the question around: what makes you want to have this html snippet inside a function?
Honestly, I just enjoy trying out my options. For this project I wanted to see if a site with one template file and a few view functions might be more efficient than multiple template files and no view function. It might be, it might not...that's the fun of it.
I always get great feedback here...that's why I bring it up.
arborint wrote:My main question is whether it is more maintainable to do the same thing using a general Template class/function that loads a PHP template (or some other kind of template). Then you don't have to write custom functions each time.
Good point, since I work on my own, I often don't consider maintainability...
You are separating or structuring at a sub routine level, its better then spaghetti code but how are you implying this provides an advantage over MVC? You've demonstrated with psuedo code a model / view separation at the sub routine level, you're probably calling this class from a set of page controllers, right?
What happens if 2 unrelated classes need to generate similar HTML, you certainly wouldn't commit the design sin of just pushing the HTML generation higher up the class hierarchy right?
psurrena wrote:This has been brought up before, especially in my previous questions, and I've finally implemented it. What is everyones opinion on a function or class dedicated to view? I use the below function within a template, instead of creating an additional template file.
I guess my big problem is when you have a basic view structure that could be easily templated but, as in the example below, it would be very useful to be able to control the amount of list items and div tags. The code below would be for jQuery tabs.