Gallery3:Developer Handbook:URLs and URL Routing - Gallery Codex
Personal tools

Gallery3:Developer Handbook:URLs and URL Routing

From Gallery Codex

URLs and URL Routing

Gallery 3 uses Kohana's routing system to connect a url to a controller. There is a simple mapping between the URL that you see in the address bar of your browser and the function name in a controller that's executed.

For this URL:
       ^           ^        ^         ^   ^   ^
       │           │        │         │   │   ├── function arguments
       │           │        │         │   ├── function named "add"
       │           │        │         ├── controller "Tag_Controller"
       │           │        ├── main Gallery 3 PHP script, edit
       │           │            gallery3/.htaccess to remove this
       │           ├── directory where Gallery 3 is installed
       ├── hostname of your website

Gallery 3 expects that there will be a controller called Tag_Controller containing a function named add. This controller can be in any module, if there are two controllers with the same name the module load order will break the tie. Anything data after the function name will be passed to the function as arguments. In the above example, you might have the following code:


class Tag_Controller extends Controller {
  public function add($item_id, $tag_name) {
    // $item_id == 3
    // $tag_name == "foo"

When generating Galley 3 URLs, use the url::site() function from the Kohana URL helper to refer to a controller and function. For example to generate the url above, you would do:

 <?= url::site("tag/add/3/foo") ?>
 <?= url::site("tag/add/3/foo?q=1") // query params are ok ?>
 <?= url::site("items/{$item->id}") // variables are fine ?>

Gallery 3 extends the URL helper in modules/gallery/helpers/MY_url.php to add the following additional methods:

  • abs_file - same as url::file() except it returns the absolute url
  • abs_site - same as url::site() except it returns the absolute url
  • current - return the server-relative current url
  • abs_current - same as url::current() except it returns the absolute url
  • merge - same as url::merge except that it escapes XSS
  • merge_querystring - merge an extra query string into the given url