Documentation

Light-weight, fast, simple and powerful!
 
Translations of this page?:

urlById()

This function1) makes it possible always to produce a correct and current url to the page despite it possibly having moved from its original position in the page hierarchy. It does this by using the page's id.2)

See also: findById(), linkById()

Usage

<?php echo Page::urlById(3); ?>

where “3” in the example above is the “id” of the targetted page. It will produce the corresponding URL, e.g. http://www.example.com/about_us

To find out what the ID of a given page is, either look on the “metadata” tab, or hover above the page's title or icon in the main admin page listing, where the ID will appear as a tooltip.

Using a variable for the ID

Using a simple variable for the ID will not pass the filter test set by the urlById() function. In other words, something like this:

<?php echo Page::urlById($article->id()); ?>

will throw an error. It is possible to set the ID number dynamically, but it requires an extra step, wrapping the variable for the ID in with the PHP intval() function, like this:

$articleId = intval($article->id());
echo Page::urlById($articleId);

With this in place, the urlById() function will work as expected.

1) Added in Wolf 0.7.0.
2) See the "id" documentation on how to find the ID of any given page.
 
functions/urlbyid.txt · Last modified: 2013-05-04 14:24 by David
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 wolfcms.org / design by yello studio / Wolf CMS Inside