tags:

views:

58

answers:

2

Ok, so here's where I'm at. I've been studying MVC/OOP, trying to roll my own as an exercise. I think I've finally grepped the purpose of each letter in the MVC acronym - my question here pertains to a design decision.

I've set up an FC of sorts - it takes parameters from the $_GET array and loads the appropriate sub-template into a master template using an include. Each sub-template also performs a similar trick, and loads in a set of partials to allow for complex layout requirements. As I was doing this, I got the sneaking suspicion I hadn't quite grasped everything - the Model wasn't making a significant appearance (although to be fair the 'application' has little in the way of a data layer).

Then I figured I should tackle the contact form, which requires three states/views, submitted with no errors, submitted with errors, and not submitted. I've seen a number of approaches to this problem, and I wanted to get some feedback. What I intend to do is load a controller within that partial that handles the view selection based on the request data.

I looked at application controllers, but the examples I've seen simply loop through a whole bunch of commands, and I figure I only want to execute a command/control per partial, so I'm not sure if this is the right way to go.

So, my question is:

  1. what would you recommend?
  2. How would you define the component I've described, is it a controller, a command pattern, or a filthy Page Controller?

Caveat: The "application" is nothing more than a basic brochure site, but I wanted to tackle something simple to grasp the concept.

A: 

what would you recommend?

the contact form, which requires three states/views, submitted with no errors, submitted with errors, and not submitted

  1. not submitted (view = form)
  2. submitted with errors (view = form, for each error -> show error)
  3. submitted with no errors (view = form_success)

This way you only need 2 views.

How would you define the component I've described, is it a controller, a command pattern, or a filthy Page Controller?

Controller, unless Controller != filthy Page Controller - if so I have no idea.

Alix Axel
how would you recommend I invoke partials?re: filthy Page Controllers - I gather from various sources that Page Controllers are regarded with disdain - is this warranted?
sunwukung
In the scenario you described there is no need to invoke partials. There is nothing wrong with Page Controllers, what I meant was the that in my understanding all controllers should be page controllers, otherwise what are they?
Alix Axel
I appreciate what you're saying - but say you want to have several application elements on a page - a gallery of images, a contact form, a blog roll. If you use a single Page Controller/View for each page (and as I understand it's implementation) bloated with conditionals. The command pattern seems to be more lightweight in that it can cater for each portion of a View individually, and allow reuse of partials between pages without excessive duplication. Yet you could just include a conditional for each partial. I'm just trying to figure out which is "best".
sunwukung
errata: "If you use a single Page Controller/View for each page (and as I understand it's implementation) it could end up bloated with conditionals."
sunwukung
I don't see controllers (or page controllers - what is the difference again?) bloated with conditions. You have Controller -> Method (Action) -> Conditions (if necessary) + Logic -> Views -> Partials, seems "clean enough" for me.
Alix Axel
I think perhaps we're talking at cross purposes here.
sunwukung
A: 

After much research, this - I believe, is the answer I was looking for:

http://java.sun.com/blueprints/corej2eepatterns/Patterns/CompositeView.html http://java.sun.com/blueprints/patterns/CompositeView.html

sunwukung