Links
The generation of links or URLs is as old as the history of the dynamic web applications themselves.
The requirement for such a tool is easy compared with the complexity of the implemention:
manipulate existing URLs to generate new ones. This functionality is included in the
linkHandler component of the adventure php framework. The class gives the opportunity to
deal with URLs and alter or delete their paramaters.
The following example shows the case of generating a link for a button in the guestbook application
included in this page. There a basic URL taken from the $_SERVER array is processed by the
generateLink method. The second parameter of the linkHandler's
function indicates the parts of the URL that should be added or replaced by the given key-value-array.
The source code of your application may therefore contain the following lines:
$EntryID = '4711'; echo linkHandler::generateLink( $_SERVER['REQUEST_URI'], array( 'view' => 'deleteentry', 'entryid' => $EntryID, 'action' => '' ) );
In this example the resulting URL will contain the parameter view with the value
deleteentry and entryid with the value 4711. The
parameter action is deleted from the URL whatever the parameter was included in the
basic URL or not.
To use the linkHandler component it must be imported using the
import('tools::link','linkHandler');
code fragment. Due to the fact, that this class is a static class, it can be used anywhere.
For the generation of front controller compilant URLs, the frontcontrollerLinkHandler
component was introduced. For details concerning this class please refer to the
front controller page, chapter 1.4.
Comments
Do you want to add a comment to the article above, or do you want to post additional hints? So please click here. Comments already posted can be found below.
There are no comments belonging to this article.
|