Re: Newbie - Redirect to do processing



hajaansh@xxxxxxxxxxxxxx wrote:
Hi there,

I am creating my own php site but am a bit concerned with putting all
form processing into a page that is also displaying stuff (i get
overwhelmed with very long pages and like to separate processing from
displaying for maintainability). I found a possible way of separating
processing through using a redirection such as:

    header("Location:" . mylocation);

so if i was logging into my site instead of going straight to the page
it needs to go to and doing all the post processing there I would have
a "processing page" which would redirect me to the correct location
perhaps depending on what was written. So if the incorrect password was
given it would go to an error page otherwise the user would be
successfully logged in. My processing pages would be in effect the
controller in the MVC pattern.

I was wondering if there were any problems people see in this and in
what situations people use it if at all and in which cases not. It
seems a misuse but if it works....who cares?

It may even be standard practise but I have looked at quite a lot of
open source php projects and found that most people do a lot of
processing in the pages that do the displaying.

Cheers for all your advice,

funky


I don't think doing everything in one place is a good way. That's why they invented MVC :)
Anyways, one way would be:


Have a control url parameter, say, page.
Define an array like this:

$pages = array(
  "id1" => "class1",
  "id2" => "class2",
  ...
  "idN" => "classN"
);

Now have a script retrieve the url parameter, and instantiate the respective class. Have all classes have a method to output content:

$id = $_REQUEST["page"];
$class = $pages[$id];
$obj = new $$class();
$obj->output();

The script will be your controller, the array will be the model, and the classes will be the viewports, perhaps together with persistence layer.

This is, of course, overly simplified :)


luph .



Relevant Pages

  • Re: MVC - The right way
    ... >> You might also put the populating code into a controller class, then subclass ... >> populates the currency popup. ... Why should a combo box displaying currencies *care* whether ... and put the smarts in the controller. ...
    (comp.object)
  • Newbie - Redirect to do processing
    ... I am creating my own php site but am a bit concerned with putting all ... overwhelmed with very long pages and like to separate processing from ... displaying for maintainability). ... processing through using a redirection such as: ...
    (comp.lang.php)
  • Re: Autoraid 12H LUN identification
    ... >execute arraydsp -a the SCSI path is not displayed. ... >know how to associate a hardware path with an array serial number. ... path you can match it up to displaying it by S/N. ... Controller X Product ID = C5447A ...
    (comp.sys.hp.hpux)
  • Re: MVC: Internationalize Controller?
    ... suggests that it should focus solely on displaying to the user whatever it is given by the controller. ... In other words, it should be the Controller that determines the precise message to display, i.e., it is the Controller that localizes any messages. ... E.g. controller (presenter) can tell the view something like - present the data for the person named "John Doe", and it is then implementation detail of a view wheteher, it will output something like: ... However, if one uses separate resources packagecontaining hardcoded texts, localization simply amounts to delivering of different resource package, while both view and controller remain unchanged i.e. independent of text messages. ...
    (comp.object)
  • Re: MVC: Internationalize Controller?
    ... suggests that it should focus solely on displaying to the user whatever it ... is given by the controller. ... You seem to have a Controller confused with a Presenter. ... In MVC the ...
    (comp.object)