Page 1 of 1

Is URL construction Business or Design Logic?

Posted: Sun May 01, 2005 1:27 pm
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?

Posted: Sun May 01, 2005 2:18 pm
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..

Posted: Tue May 03, 2005 5:20 am
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.

Posted: Tue May 03, 2005 2:21 pm
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?

Posted: Wed May 04, 2005 3:24 am
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.

Posted: Wed May 04, 2005 4:02 pm
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.

Posted: Wed May 04, 2005 4:06 pm
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)

Posted: Wed May 04, 2005 4:12 pm
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.

Posted: Thu May 05, 2005 1:47 am
by patrikG
You can download Exclipse at http://sourceforge.net/projects/eclipselib/ - very nice set of classes.