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.
<?php
include 'includes/app.php';
$display->page_title = 'Welcome!';
$display->content = 'This is the content';
$display->display();
?>
My questions are:
What is the best way to populate the $display->content?
What is the best way to organize the classes so that I can dynamically create menu's based on the following factors. 1. The page they are viewing, 2. The type of user that is logged in. 3. Assign a custom order to the menu's
MenuItem and Menu classes where MenuItem can contain other MenuItem objects. When adding MenuItems, it or some other class should determine if that item should infact exist based on your criteria. When and where this happens can be moved around, but I needed to convey the idea.
Ok, now what would be the best way to create template files for each page and for the menus? I figure I can't just use a regular template because I need to buffer the content so I can cache pages when needed. I know I can buffer (ob_start, ob_end_flush) the templates and pull that into a variable but I'm thinking there is a better way.
Better template classes. What I mean is, at least to me, a template class returns output generation to its View. Not necessarily calling the view, but just returning the resulting string(s) or an array, something.
I don't have any examples I can go that'd make any lick of sense, so I'll try to explain how it all works.
Lets say I add a text field to the current window (page.) During rendering each renderable object is tallied into a distinct list of what render classes to load. Each of those classes is then loaded only once. When the renderer reaches the text field, it tells the text field render object to process the text field object. The render object interrogates the various settings of the text field. Information like it has a label, label text, label position, does it have hinting and so forth is pulled out and run through the standard output that covers that information. The output may be as basic as a standard <intput type="text">, but it could also be more complex with a <label> or some other control(s) attached to it.
All this guarantees me the same handling for that object 100% of the time. And that's what I'm making sure happens: consistency. Don't get me wrong, I have skins (templates and color changes) so I can change the visuals on a whim, but that doesn't change how the rendering is handled.
You might want to try hierarchical Views. They can be as simple as templates within templates. For example, say to top level template looked like this:
arborint wrote:Why do you want to cache pages? I would suggest getting the design right and then adding caching as necessary if you have performance problems.
I've got my reasons. I'm building a large site which will have a ~20gb database full of content that doesn't change very often. Since there would be a tremendous amount of data being requested from the database server, I'd like to minimize this by implementing a cache. The data will hardly ever change, so I might store the bulk of it in files instead of the database, then only store the reference in the database, but either way I would like to figure this out.
astions wrote:Ok I don't want to start a new thread, let me ask this a different way....
What is the best way to retain the ability to cache pages when using the MVC pattern?
I dont know if you are using your own MVC framework, but this comparison of well known frameworks shows 6 which it is claimed contain MVC and some kind of cacheing mechanism:
Yossarian make an excellent point. In particular, using a Front Controller and an inherited base Action Controller gives you two clean points to inspect to request and decide of the requested page is in the cache or needs to be generated. If you architecture is designed right the caching layer can make that decision and if necessary turn on output buffering or grab the output from a Response object to transparently get the page and save it to the cache.