Links

The information provided on this page is deprecated since release 1.14. Please refer to the Links (since 1.14) chapter.

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:

PHP-Code
$id = '4711'; echo LinkHandler::generateLink( $_SERVER['REQUEST_URI'], array( 'view' => 'deleteentry', 'entryid' => $id, '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
PHP-Code
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.