Page 1 of 1
Front Controller
Posted: Tue Sep 19, 2006 10:15 am
by psurrena
Can someone please help explain the best way to approach a Front Controller? How would one set up multiple MySQL queries in the simplest manner?
Posted: Tue Sep 19, 2006 1:01 pm
by GeXus
Not sure if this is what you want.. but you could use a wrapper class, stored procs, or keep all queries in one page, then call them as needed.
Posted: Tue Sep 19, 2006 1:05 pm
by Christopher
It is not clear how implementing a Front Controller and setting up multiple MySQL queries are related from your questions. Those are usually highly separated parts of an application. Can you clarify?
Posted: Tue Sep 19, 2006 1:09 pm
by Luke
arborint wrote:It is not clear how implementing a Front Controller and setting up multiple MySQL queries are related from your questions. Those are usually highly separated parts of an application. Can you clarify?
that was exactly what I was thinking... what does a front controller have to do with mysql queries??
Posted: Tue Sep 19, 2006 1:21 pm
by psurrena
I'm asking because the idea of a front controller is new to me. So you're telling me a front controller is only for templating purposes which generally would have nothing to do with MySQL queries, right?
Posted: Tue Sep 19, 2006 1:22 pm
by RobertGonzalez
For the time being, take your thought of database interaction out of the picture.
Posted: Tue Sep 19, 2006 1:27 pm
by Luke
psurrena wrote:I'm asking because the idea of a front controller is new to me. So you're telling me a front controller is only for templating purposes which generally would have nothing to do with MySQL queries, right?
no... a front controller simply presents a central point of access for all incoming requests... so all requests are handled in the same manner by the same set of code.
Posted: Tue Sep 19, 2006 1:28 pm
by psurrena
It would store classes and functions?
Posted: Tue Sep 19, 2006 1:40 pm
by Christopher
Not for templating purposes and it does not store anything. A Front Controller centralizes the request from the browser is sent to a single script that sorts out what to do with it (based on pre-defined parameters). Probably the most confusing thing about implementing the Front Controller is that it is it is a solution to a problem with another pattern -- the Page Controller. Most patterns are solutions to problems and if you don't have the problem you don't need the pattern. The are not very helpful in isolation.
Most PHP sites use the Page Controller pattern and implement multiple PHP scripts, each as an entry point for the application. The problem occurs that as the app gets bigger or more complex you can get lots of duplicated code unless you are very disciplined. The Front Controller pattern help reduce the amount of duplicated code by providing discipline through the sturcture it provides.
Posted: Tue Sep 19, 2006 1:54 pm
by Luke
Generally if you see an application which you never leave the index page:
http://www.someapplicationsite.com/inde ... tuff&id=23
That application has implemented a front controller... you never enter the application from any other point... just index.php... but your request can change... you can change the action, params, and id... and this will be handled by the front controller.
Posted: Tue Sep 19, 2006 4:17 pm
by psurrena
Thank you for the info. Is there any book or site that deals with this particularly well?
Posted: Tue Sep 19, 2006 4:34 pm
by Luke
search google and this site for both "php design patterns" and "front controller" both will return many many results
Posted: Wed Sep 20, 2006 2:59 am
by CoderGoblin
I found
Understanding MVC in PHP useful when I started looking at this subject.
Posted: Wed Sep 20, 2006 10:16 am
by RobertGonzalez
That was a great article. I think I myself might look into that book.