. Updated Daily. Editions SDA India   SDA Indonesia
BUSINESS ENTERPRISE SOLUTIONS ARCHITECTURE INFORMATION SECURITY WIRELESS & MOBILITY DATA & STORAGE DEVELOPMENT HARDWARE













News

Monday, 9 April 2007

Article: URL Routing with PHP- Part 2

 

 

Doug Hill in a new post has bring in the second part of the URL Routing with PHP. In the second part of the series explains the basics that he covered in the first part.

He describes the tutorial under the following heads:

Assign Responsibilities

He points out a problem here. He says, a problem occurred in the first part with two different things going on with the script. Firstly, the parsing of the URL to obtain a command array and the second thing is that the actual dispatch of the command by the switch statement. He says, his motive is to create an architecture that easily allows changing the way incoming URLs are formatted, and also the substitution of alternative dispatch schemes.

Standardized Command Objects

So, to achieve the above goal, he creates a standard command object. This will allow changing the way the URLs are interpreted or dispatched as long as the interpreter creates command objects and the dispatcher accepts them, he says. He also gives an example code to illustrate it.

Interpreting URLs

In this section he shows a class that handles interpreting the incoming URL and creating a command object. He uses a class that follows the same method as in part one and creates commands based on a simple format for the incoming URL, a command followed by its parameters separated by forward slashes ‘/’.

Dispatching Commands

The above step enables to pass the command object to the dispatcher. He uses a switch statement that includes different scripts based on the command.

Put It All Together

He reminds you that in the first part of this series he used an .htaccess file to redirect to index.php. He uses the same .htaccessfile for the second part of the tutorial also. But he let’s you know that the new index.php will look a bit different. He informs you that after carrying out the changes in Part one, you can substitute different classes to handle the interpretation of URLs or command dispatching easily.

 

Read the Article

 

Related Reading: Learn About URL Routing with PHP

 
 
print save email comment

print

save

email

comment

 
 

Search SDA Asia

Free eNewsletter

SDA Asia Magazine Free Download
 
 
 
Copyright @ 2009 SDA Asia Magazine - All Right Reserved Privacy Policy | Terms of Use