Database Reference
In-Depth Information
So, for instance, a URL ending with /apps/myapp/a/b/c.xq will have eXist looking
for a controller.xql file in /db/apps/myapp/a/b , /db/apps/myapp/a , and finally
in /db/apps/myapp (where it will most probably be).
• If eXist does not find a controller, it uses the URL as a path into the database and
tries to find a matching resource.
Only one controller will be applied to a given request. It is not possible to pass con‐
trol from one controller to another (or back to the same).
However, be aware that when your controller asks for a redirect (using the redirect
element, as discussed in “Redirecting the request” on page 201 ), the browser will fire a
new request and the whole circus of finding and possibly running a controller will
start again. This creates the potential for redirect loops, so be careful!
The URL Rewriting Controller's Environment
The URL rewriting controller in controller.xql gets information about the request
through five external variables. You do not need to explicitly declare them, but if you
do it should look like this:
declare variable $ exist:path external ;
declare variable $ exist:resource external ;
declare variable $ exist:controller external ;
declare variable $ exist:prefix external ;
declare variable $ exist:root external ;
Besides using the special controller external variables, you can also
use the functions in the request extension module (see “The
request Extension Module” on page 209 ) to find out more about the
request and the URL.
If you want to play with these variables, the collection /db/apps/exist-book/building-
applications/show-controller-variables contains an example that passes the values of
the external variables to the show-controller-variables.xq script, which displays them
on an HTML page.
You can use this little application to inspect the values of the URL rewriting control‐
ler's external variables. Use your browser to visit http://localhost:8080/exist/apps/
exist-book/building-applications/show-controller-variables/<any-path-you-like> , and
the values of the variables will be displayed.
Here are the definitions of the variables. For the examples, we assume you have
browsed to http://localhost:8080/exist/apps/exist-book/building-applications/show-
controller-variables/a/b/c.xq :
Search WWH ::




Custom Search