Skip to end of metadata
Go to start of metadata

First Steps

Before we go much deeper into Okapi, we'd like to explore this basic setup a little bit.

The commandmap

In conf/commandmap.php you find the "control centre" of Okapi, the so called commandmap. In the commandmap you define what should happen on which request. Currently it will look like:

This tells Okapi, that for every request (route('*')) it should use the command default (in the class api_command_default) and use the xslt default.xsl (in the themes directory)

Let's extend it with a new route. We want, that for every request on /tutorial/, it calls the command "tutorial" view the xslt tutorial.xsl, then we have to write the following and put it before the above route (as the '*' matches everything and Okapi just goes through the commandmap until something matches)

The commandmap is pretty powerful, you can read more about it at Commandmap.

The commands

Commands are one of the core components in Okapi and usually handle the requests and generate the content (together with the optional models).

A very very simple command could look like this

This one just generates a short DomDocument and returns that to the controller in getData()

Now you can see the output of this at http://okapitutorial.lo/tutorial/?XML=1

XML=1

For making ?XML=1 work (it usually shows you the XML just before the XSLT transformation, very handy for writing the XSLTs), you have to add

    allowDomDump: true

to your config.yml, eg. in conf/config.d/00-config.yml

The views

In a normal, xslt template based setup, the default view is more than enough for a start. For outputing the content produced in the tutorial command, we have to write a corresponding xslt (eg. in themes/default/tutorial.xsl), which could look like the following:

Now go to http://okapitutorial.lo/tutorial/ and watch the full glory.

You just made your first complete Okapi output.

XML and XSLT are optional

While the above example is based on XML and XSLT (and that's what we at Liip usually use and like) Okapi doesn't insist on that. You can just pass aronud arrays, strings or whatever you like between the commands and the views. You just have to adjust the view to do the right thing. You'll see an example later in that tutorial.