Page 1 of 1
is redirection allowed from business logic?
Posted: Thu Jun 28, 2007 3:31 pm
by raghavan20
i will explain the situation.
i have a controller for checkout that does call a lot of business logic like
1. get card object to pay for order
2. create order object
3. pay for order
4. update listing quantities
5. ----------
this 'pay for order' is implemented by a set of classes in business logic. with recent changes in payment processing, there has a risen a condition where the payment gateway checks whether additional 3D check is enabled on that card. if enabled, we have to pass control to a new script/controller which will do further processing. if 3D check is not enabled, the rest of the business logic is completed and control will be returned to the same controller that called the business logic.
now my question is
1. can we allow business logic to do header redirect to a different controller or the business logic have to inform the original controller to redirect to a new controller by returning some appropriate values for the controller to understand redirection?
Posted: Thu Jun 28, 2007 7:07 pm
by Christopher
I don't exactly follow your specifics, but I would look into forwarding, hierarchical controllers or an Application Controller instead of redirect. That said, I don't think redirect is necessarily a problem in that it is simply a forward without context. I would have the Model signal that a forward is needed, but have the Controller and View actually handle it.
Posted: Fri Jun 29, 2007 1:54 am
by raghavan20
so you saying that Model can inform ApplicationController to make a redirect. I am not much aware of ApplicationController, have you got any good material to learn about it. Where can I find a php version of ApplicationController so that i can know how it is built and the various functions that it could perform.
my general question was, whether redirection could be allowed directly from a Model eventhough i know it works.
thanks for your reply.
Posted: Fri Jun 29, 2007 2:11 am
by Christopher
raghavan20 wrote:so you saying that Model can inform ApplicationController to make a redirect. I am not much aware of ApplicationController, have you got any good material to learn about it. Where can I find a php version of ApplicationController so that i can know how it is built and the various functions that it could perform.
It is a complex pattern and I don't know a good example. Typically in PHP it is a simple Controller that maintains its state in the session and controller other controllers.
raghavan20 wrote:my general question was, whether redirection could be allowed directly from a Model eventhough i know it works.
I would have the Model inform the View or Controller to do the redirect. You will need to decide whether the redirect is a response or program flow.
Posted: Fri Jun 29, 2007 3:10 am
by raghavan20
arborint wrote:raghavan20 wrote:so you saying that Model can inform ApplicationController to make a redirect. I am not much aware of ApplicationController, have you got any good material to learn about it. Where can I find a php version of ApplicationController so that i can know how it is built and the various functions that it could perform.
It is a complex pattern and I don't know a good example. Typically in PHP it is a simple Controller that maintains its state in the session and controller other controllers.
I think there is a section on applicationcontroller in poeaa and in zend framework; i will try to read them
arborint wrote:raghavan20 wrote:my general question was, whether redirection could be allowed directly from a Model eventhough i know it works.
I would have the Model inform the View or Controller to do the redirect. You will need to decide whether the redirect is a response or program flow.
what do you mean by response and program flow? i am sorry i could not understand the distinction.
Posted: Fri Jun 29, 2007 6:20 am
by jeffery
what I normally do for my Application is as follows:
Controller knows when to do the re-direct
Controller tells View to re-direct
The View asks the Model where to re-direct to and executes the re-direct.
cheers,
Jeffery
Posted: Fri Jun 29, 2007 6:44 am
by raghavan20
jeffery wrote:what I normally do for my Application is as follows:
Controller knows when to do the re-direct
Controller tells View to re-direct
The View asks the Model where to re-direct to and executes the re-direct.
cheers,
Jeffery
as you have been telling that controller should be aware of redirection. i think that i should not make business logic ask controller to redirect. may be i think, i could raise an exception from business logic/Model and controller would handle this exception by taking appropriate steps and redirecting to different page/controller.
i do not personally understand why a view should be involved in redirection as controller can do it. can you give an example how you do the above procedure you mentioned?
Posted: Fri Jun 29, 2007 11:24 am
by Christopher
The Model should just indicate that a certain condition exists -- the Controller or View can then decide what to do in that condition.
Redirects are strange because they are done with the HTTP response that is sent back to the browser -- so they technically should be "built" by the View. But they are really program flow so they can be thought of as part of the Controller's responsibility. This is where a HTTP Response object makes things clearer because it creates something that both the View and Controller can talk to.