some object properties

Properties Generated By getBaseUrl()

Berylium objects exist in the database, outside of any sort of defined namespace. One of the tasks that is carried out on each object as it is loaded into memory is that the getBaseUrl() method is called on it, to build a set of URLs that can be used to refer to the object within your contexts.

As a developer, it is important to have some idea which namespace to use in what situations-- should you use $this->staticUrl or $this->baseUrl? This document will serve as a definitive guide.

Problem Is...

Any Berylium object has a number of different URLs, that may be valid in any or all situations. The differences can be found in the current connection (http, https, or inherit), scriptname (none or inherit/be2), and format (html, native, or inherit). Inherit just means that the URL will have the same connection, format, etc. as the current request-- if this is http, the generated url will also be http.

That's roughly eight different factors on three attributes, for a total of twnety-four different URLs if you were going to build them all at once:

http-noscript-html
https-nocscript-html
inherit-noscript-html
http-be2-html
https-be2-html
inherit-be2-html
http-noscript-native
https-nocscript-native
inherit-noscript-native
http-be2-native
https-be2-native
inherit-be2-native
http-noscript-inherit
https-nocscript-inherit
inherit-noscript-inherit
http-be2-inherit
https-be2-inherit
inherit-be2-inherit
Nice, huh? Not.


The getBaseUrl() Approach

$this->getBaseUrl() creates a combination of URL parts -- just the path with no connection or format -- and ready-built shortcuts to the most often-used URL schemes.

You get:
  • staticPath = none-noscript-none
  • bePath = none-inherit-none
  • staticUrl = http-noscript-native
  • htmlUrl = http-noscript-html
  • idUrl = http-be2-html
  • beUrl = inherit-inherit-native
  • baseUrl = inherit-inherit-inherit
  • path = path to attachment

The first two (staticPath, bePath) are to be used as building blocks, for when you need to specify connection and/or format explicitly. staticPath is prefereable since it will take advantage of the cache in situations where it exists.

staticUrl, htmlUrl, and idUrl are best for references that will be used in emails and on external sites. idUrl is the same as the permalink, and will always get you to the object, even if it moved within the folder heirarchy.

The difference between staticUrl and htmlUrl is that staticUrl will take the user directly to a binary object in case of attachments, whereas htmlUrl will always go to the descriptive HTML page.

Finally, beUrl and baseUrl should be used for generic links within Berylium so that scriptstate and, in the case of baseUrl, the current format, are inherited from request to request. This will allow you to stay within popup format from link to link, for instance.

The URLs are cached, so even if you call getBaseUrl() again, the script won't take the time to regenerate them. In the rare case that they might have changed, such as after updating an object with a new name or parent folder, you can force regneration by calling it with a single argument, like $this->getBaseUrl(1);


Example: Image

Given the current request: https://sitename/be2/folder/name/index.popup, here are the URLs as they might apply to image:42 (sample.jpg) from the database:
  • staticPath = /folder/name/image-sample
  • bePath = /be2/folder/name/image-sample
  • staticUrl = http://sitename/folder/name/image-sample.jpg
  • htmlUrl = http://sitename/folder/name/image-sample.html
  • idUrl = http://sitename/be2/image-42.html
  • beUrl = https://sitename/be2/folder/name/image-sample.jpg
  • baseUrl = https://sitename/be2/folder/name/image-sample.popup
  • path = $beryliumroot/files/sitename/yyyy/mm/image-42


Special Case: Folders

Folders are a special case because they use the pseudoname "index" to refer to themselves and provide a hook to hang the format on.

Given the current request: https://sitename/be2/folder/name/index.popup:
  • staticPath = /folder/name
  • bePath = /be2/folder/name
  • staticUrl = http://sitename/folder/none/index.html
  • htmlUrl = http://sitename/folder/none/index.html
  • idUrl = http://sitename/be2/folder-42.html
  • beUrl = https://sitename/be2/folder/name/index.html
  • baseUrl = https://sitename/be2/folder/name/index.popup
  • path = null (this will change soon!)


Special Case: the Site

Sites are a special case because they mostly mirror the top-level folder ("/"), except where they don't. mostly because no native format is assumed.

Given the current request: https://sitename/be2/folder/name/index.popup:
  • staticPath = /
  • bePath = /be2/
  • staticUrl = http://sitename/
  • htmlUrl = http://sitename/index.html
  • idUrl = http://sitename/be2/site-42.html
  • beUrl = https://sitename/be2/
  • baseUrl = https://sitename/be2/index.popup
  • path = null

By Chris Snyder on June 25, 2003 at 7:03pm

jump to top