New class URL and API::getDestinationURL()

Saturday, April 17th, 2010|Core changes, Version 3|by Romans

For a while now, many parts of library relied on function API::getDestinationURL($page). This function returns the valid URL which will point to specified page. However the implementation of this function was only working for absolute page names, and was built-in into API.

I am adding implementation which relies on a new class called URL. This class instance will be returned by getDestinationURL(). If you happen to pass this object to getDestinationURL again, it will not going to mess up the URL anymore.

Apart from that – additional syntax for relative pages is now allowed.

  • pagename – will link to absolute page /pagename
  • /pagename – same as above
  • ./pagename – will link to a relative page. If our current page is users/add, then link will point to users/pagename
  • ../pagename – will go one level up. You can use ../users to return from users/add to list of users.

URL generation supports sticky arguments and will also properly determine base URL. The returned URL will be absolute with “http://” (or https) in front.

3 Comments

Svetlozar Kondakov
Posted April 19, 20105:46 pm

This is long awaited update IMO. This method also messed up usage of ApiWEB in the past as I remember.

jancha
Posted April 20, 201011:16 am

very cakey, I’d say.

romaninsh
Posted April 21, 20101:59 pm

jancha, actually other things work in a similar way. js chains convert themselves into strings. dynamic queries don’t but i think they should. Also echo $tempate should produce a rendered template.