index.php?somevar=somepage linking

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

psatish wrote:I have implemented the same after reading all the discussions. So now all my pages are channelled through index.php with a querystring showing what page to be loaded.

But I think my application design has to be more tightly OOP-ed to take advantage of such designs.
There are many discussions and examples of implementing a Front Controller in PHP. You might want to search the web for examples.
psatish wrote:MURPHY'S LAW - WHEN YOU HAVE A HAMMER IN YOUR HAND EVERYTHING LOOKS LIKE A NAIL
Actually that's not Murphy's Law, that's a proverb about narrowmindedness. Murphy's Law is: "If anything can go wrong, it will" and was about taking into account all potential points of failure when engineering something.
psatish
Forum Newbie
Posts: 7
Joined: Tue Sep 27, 2005 6:34 am
Location: Hyderabad, India
Contact:

Post by psatish »

arborint wrote:Actually that's not Murphy's Law, that's a proverb about narrowmindedness. Murphy's Law is: "If anything can go wrong, it will" and was about taking into account all potential points of failure when engineering something.
Yes, quite true but I remember to have read it in the Murphy's Laws series but was too lazy to actually find out who said it :P

Will change it though :D
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Post by alvinphp »

arborint wrote:There are many discussions and examples of implementing a Front Controller in PHP. You might want to search the web for examples.
I have been coding this way (Front Controller Pattern) for quite a while, but never had a name for it. I don't know if I feel smart for doing it this way or dumb for not knowing a pattern already existed for this.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

I think every PHP programmer feels that way after they work though several patterns for the first time. Your first reaction is say "DOH!" and the second to kick your shins for not researching patterns sooner...;)

I see nothing wrong with passing page via a query string - it's what all my own front controllers do. Generally my pages are referred to as:

index.php?action=index.display (the default page for index.php (if no querystring)) or game.php?action=fleet.attack&fid=3, etc.

In this case, the FC would delegate to the relevant Command object - i.e the Attack Command of the Fleet Module. Don't worry about that level of design though ;) I do it the seemingly complex way since I use FC as part of a broader pattern...

I don't use mod_rewrite on the basis it exists to make things "pretty". I see little added security unless you wish to obscure page flow to a user who has no clue about mod_rewrite. It's one of those developer preferences you sometimes see argued to death on forums...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

psatish wrote:Yes, quite true but I remember to have read it in the Murphy's Laws series but was too lazy to actually find out who said it :P
They are both good advice for programmers :D
Post Reply