ObjectOrientedURLs

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
driverdave
Forum Newbie
Posts: 3
Joined: Sun Sep 20, 2009 6:54 pm

ObjectOrientedURLs

Post by driverdave »

I had a couple of annoyances when writing object oriented websites.

The first was lots of php files that did little more that instantiate my class. Having all these little files all over the web server seemed like an awful lot of clutter, and unnecessary.

The second was using mod-rewrite to create friendly URLs. Whenever I made a new friendly URL, I had to go in and edit the rewrite rules & restart the web server. So I wrote ObjectOrientedURLs

ObjectOrientedURLs lets you call class methods directly from URLs, without having to upload a PHP file that instantiates your class and calls the method. All you need to to is write method names that match up to the URLs on your website. To make a new page, all you need to do is write the class method and upload your class to the server.

I'd love to get a few eyeballs on the code, and some feedback.

You can check out the code and download the class, along with the .htaccess file, below.

http://www.davecomeau.net/blog/17/PHP+C ... ientedURLs
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: ObjectOrientedURLs

Post by Darhazer »

You need to take a look to the existing routers / front controllers before reinventing the wheel.
driverdave
Forum Newbie
Posts: 3
Joined: Sun Sep 20, 2009 6:54 pm

Re: ObjectOrientedURLs

Post by driverdave »

can you point me to one? i'd love to see what i'm re-inventing.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: ObjectOrientedURLs

Post by Darhazer »

CodeIgniter? and probably any MVC framework out there :)
driverdave
Forum Newbie
Posts: 3
Joined: Sun Sep 20, 2009 6:54 pm

Re: ObjectOrientedURLs

Post by driverdave »

cool, thanks for pointing that out.

i can see my class has some characteristics of CodeIgniter. i'm not a huge fan of frameworks, and one of the reasons i wrote my class is to cut down on the amount of files on the server. it's my personal preference. i could rant on and on about PHP frameworks.

anyways, i guess i've received a coding critique, so thanks for the responses. i think i was wanting more of a critique of the actual code, but this will do for now.
Post Reply