Iliad Framework, on controllers

In the previous post about the Iliad Framework we build a basic web application that, in the default controller, write an “Hello World” HTML.

Now we will try to clarify how the Front Controller framework works. Every controller (remember that it must be in the controllers protocol) is mapped to a “page” of your application.

These things are best explained with an example. A controlled named firstTest in an application whose path method returns leonardoBlog will be mapped to the URL leonardoBlog/firstTest.

In the same way the controller secondTest will we mapped to leonardoBlog/secondTest. The only exception is the index controller that being the default controller is mapped to the application URL: leonardoBlog. Enough said. Let’s add some code to our application.

We create another controller named firstTest like this:

<span class="c">"LcBlogHelloIliad>>firstTest (protocol controllers)"</span>
<span class="nf">firstTest</span>
    <span class="o">^</span> [ <span class="o">:</span><span class="nv">e</span> <span class="o">|</span> <span class="nv">e</span> <span class="nf">h1:</span> <span class="s">'This in the first test'</span><span class="p">.</span>
    <span class="nv">e</span> <span class="nf">a</span> <span class="nf">linkToLocal:</span> <span class="s">'index'</span><span class="p">;</span> <span class="nf">text:</span> <span class="s">'Go to the index controller'</span> ]

Now if we go to http://localhost:7070/leonardoBlog/firstTest we should see the result of the new controller.

We also created a link to the index controller using the method linkToLocal: of the ILLinkableElement class. Note that we haven’t specified the URL of the application. If you will need to change the url of the application you will not have to remember when you have put the application name.

We can also modify the original index controller to include a link to the firstTest page like this:

<span class="c">"LcBlogHelloIliad>>index (protocol controllers)"</span>
<span class="nf">index</span>
    <span class="o">^</span> [ <span class="o">:</span><span class="nv">e</span> <span class="o">|</span> <span class="nv">e</span> <span class="nf">h1:</span> <span class="s">'Hi world!'</span><span class="p">.</span>
    <span class="nv">e</span> <span class="nf">a</span> <span class="nf">linkToLocal:</span> <span class="s">'firstTest'</span><span class="p">;</span> <span class="nf">text:</span> <span class="s">'Go to firstTest controller'</span> ]