Hello everyone,

I was babbling with a fellow PHPer about the Response object and how it fits inside a front controller | application controller | model | view implementation of PHP.

I've seen it mentioned in other threads, but it was never denied or confirmed that it was right.

Basically what I see happening is this:

1) The front controller is instantiated agregating an Empty Response object (which is just a data space) and a Request object (which is a wrapper for URI and POST data).

PHP Code:

= new FrontController(new Request(), new Response()); 
2) The front controller reads the request and Composes an Application Controller based on the first segment of the URI which has been mapped as "Controller" in the request object. The Response and Request Object is passed into the Application Controller during composition.

3) The Application Controller uses the Request object to select a method to run. (I'm still a little scared of the Command pattern, I get the feeling that I'll get lost in all the commad files and my multiple application controllers would seem redundant when I use this pattern) - this is for another post however, let's just suffice to say that the Application Controller selects a method to run from itself using the second segment of the URI which has been mapped as "Action" in the request object.

4) Inside the action/method called, a model is created using factory method

PHP Code:
class Base_App_Controller 
extends App_Controller

//... other classes here

private function _get_model($model) {
$model ucfirst($model) . '_Model';
    return new 
$model(DB::get_instance(), $this->_response);

5) Each Controller method is mapped to the Action parameter (which is the second segment) in the URI and manipulates the model.

While it gives commands to the model through the model's public methods, the controller lets the model do all the the processing required to prepare the data for the View.

PHP Code:
class Some_Controller 
extends Base_App_Controller
    public function 

    public function 

Here is where the Dillema is regarding the Response, Model and Request.

I could go about it three ways:

First and foremost, how I am actually doing it now - forget about the Response Object for a moment -

The controller makes one or two calls to the model which initialises it. Basically, commands it to initialise itself. For instance, a public method call from the controller (eg $this->_model->getUserData()) could abstract calls to the the following private methods:
- get_gateway() Get a Table Data Gateway
- get_by_id() Get this by ID,
- $this->set('userdata',$row_data_gateway) Store the Row Data Gateway object in your hash map as 'userdata'.

The model sets itself up and stores data in its own hash map.
The Model is then passed through to the view by the controller after the model is initialised with the $this->_model-.getUserData() call.

The View aggregates the model and accesses data through its public hash map method (get()).

The View is then acquired from the Application Controller and is invoked by the front controller.

Second approach - The model uses the Request object as its data storage, when the command is given, the Model is actually populating the request object with the Objects, Variables etc.

The View is then given the Request object instead of the Model and the View reads data from the Request object.

Again, the View is invoked by the Front Controller after being acquired from the Application Controller.

Consequently this makes me feel like I've tainted the Request Data with Response Data and separation is kind of defeated at this stage.

Third approach - The one I'm kind of considering more than the second approach. The model manipulates data and stores it inside the Response Object.

The response object is changed by the Model.
The response object is read by the View and modified by the view.
Once this is all done, The Front Controller outputs the response.

Which of the three is the correct way? Is there something I've not thought about? rules I've broken? if so then what IS the correct way?

Is there a UML diagram or article that would make everything "oh so clear"?

I've searched around as always, I spend days doing RnD before asking. But I guess I'm using the incorrect keywords. :/

Please enlighten me, thank you in advance.