Is URL construction Business or Design Logic?

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

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Is URL construction Business or Design Logic?

Post by Ambush Commander »

In a normal context URLs are very simple things.

Code: Select all

img/picture.jpg
index.html
Nothing much to see here. But then, you have the ability to put GET parameters on files, like:

Code: Select all

index.php?mode=edit
search.php?searchid=81278372&list=asc
I'm sure all of us, at one point, constructed these URLs in a fashion like this:

Code: Select all

<a href=&quote;index.php?mode=<?php
echo $mode;
if (!empty($order)) {
  echo '&='.$order;
}
?>&quote;>This is the link</a>
Of course, this presents problems if you have a page where:

- You have multiple filters that are passed through GET
- You want to have this extend over multiple pages

How do you know which GET variables to stick into the URL and which ones not to? It looks like you might want a formalized URL parsing structure.

Plus, the structure of a URL poses some interesting difficulties.

Code: Select all

index.php?param1=value1&param2=value2&param3=value3
What if paramater one is not set? Do we:

Code: Select all

index.php?param1=&param2=value2&param3=value3
...where you simply run through all the parameters

Code: Select all

index.php?&param2=value2&param3=value3
...where you simply check whether or not a paramater is used, and if not, omit the param1=value1 but not the ampersand

Code: Select all

index.php?param2=value2&param3=value3&
...where you always have a question mark, and then you just add "param3=value3&" blocks to the end.

Ideally, it would be like this:

Code: Select all

index.php?param2=value2&param3=value3
But then you need to know all the paramters being passed before generating the URL.

And you want to be able to do that last thing, but as mentioned before, you need to know all the paramters. Gone are the days now of ad hoc, you need a formalized infrastructure for URL generation (or at least dynamic URL generation)

But, if you use a templating system, does this mean:

Code: Select all

<a href=&quote;{$url.nextpage}&quote;>Next Page</a>
where we have retreated URLs to the PHP side?

Does URL construction constitute design logic, and thus must be done in the templating system and If it is business logic (aka not-design), doesn't this mean a significant viewability hit where it is difficult to custom-make URLs in new pages and it is difficult to figure out exactly where a URL points?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

imho, url building belongs in the view component
=> you offer the user an interface to the controller (which manipulates the model)

you are right that the view needs to know the exact parameters/urls/whatever to provide a correct link to the controller..
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

I'm not sure if I've fully understood the question but any html tags - including hyperlinks - are formatting and hence part of the presentation layer.

It's part and parcel of php that you have to re-create everything each request. If you have a lot of data to persist between requests sessions might be a better option than GET.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

So URLs should be simple enough in order to be implemented without an underlying abstraction system in PHP? All I have to do is pass Smarty the parameters, however ad hoc, and have Smarty and the template sort it out themselves?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

I use the Url-class of Vincent Oostindie's Eclipse library - it's fast, light and easily extensible. URLs are presentation layer in my book - all you can really do is pass some data to PHP and apart from that search engines will take the Url of a page into account when spidering, clients want to bookmark a search results etc.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Actually, that sounds pretty hopeful, but after googling around...

http://www.phpeclipse.de/tiki-view_articles.php

is this it? Because: http://www.students.cs.uu.nl/people/voostind/eclipse/ doesn't seem to exist anymore.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

if i remember well, the rfc on http recommends the following:

use GET for pages/requests that will always return (more or less) the same
use POST for pages/request that return more variable content.. (fe: updating content)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

if i remember well, the rfc on http recommends the following:

use GET for pages/requests that will always return (more or less) the same
use POST for pages/request that return more variable content.. (fe: updating content)
I'm fairly certain I understand this idea. Of course, the line is blurred when it comes to stuff like Database Intensive Searches.

My question is how to make the URLs in the first place while keeping track of what needs to be placed inside the paramaters. Doing it completely with Smarty is a plus too. Eclipse sounds hopeful, but I can't seem to find it.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

You can download Exclipse at http://sourceforge.net/projects/eclipselib/ - very nice set of classes.
Post Reply