This page is about how to define routes with Kiwa.
In Kiwa, routes are defined in the main config file. This may look like that:
<?php $config ->addPage(PageGenerator::create() ->setName('imprint') ->setLanguageCode('en') ->setChildOf('legal') ->setFile('imprint') ) ;
Here we have a page named
imprint with a language code
en. The config says, that the page is a subpage of a page with the name
Depending on the configuration of the URL structure, the example above will result in the route
setFile defines, that for this request a file named
imprint.phtml will be loaded.
If you want to know more about how to create and handle links, head over to URLs and links.
It may happen that URLs with a dynamic part have to be defined. For example, in the case of a blog that has a main page
/blog.html and an unspecified number of sub-pages, for example
/blog/hello-world.html. These pages are defined together in Kiwa.
At first comes the definition of the main page:
<?php $config ->addPage(PageGenerator::create() ->setName('blog') ->setDynamicChild('blog-dynamic-child') ->setFile('blog') // More configuration is needed here but not important for this example. ) ;
Here the method
setDynamicChild defines, that there are sub-pages allowed and should be routed into a page that is defined with the name
The example above will result in two route definitions. Depending on the configuration of the URL structure, the routes will be
Now we need the additional configuration of the sub-page:
<?php $config ->addPage(PageGenerator::create() ->setName('blog-dynamic-child') ->childOf('blog') ->setFile('blog-dynamic-child') // More configuration is needed here but not important for this example. ) ;
childOf links the page to its parent and helps to create proper URLs.
For this request a file named
blog-dynamic-child.phtml will be loaded.