Version 10, last updated by pagchen at November 07, 2011 18:11 UTC
2 The frontend
This wiki has been updated for version 0.7-alpha4
Before starting this tutorial, you should have already set up Joomla or Nooku Server, and have installed Nooku Framework. For the sake of this tutorial, we will assume that this is installed on your local machine, and can be reached at http://localhost/HelloWorld/
Component loader
The component loader is a file that basically just makes sure that incoming requests made to our blog component are handled. We won't go into specifics on that here, but to set up your component loader please create the following file:
/components/com_blog/blog.php
And then add the following line of code to the file:
<?php echo KService::get('com://site/blog.dispatcher')->dispatch();
Hello world
If you have read the Model-View-Controller article, you will know that it's the view's responsibility to render things to the screen. So that's what we'll do; create a view.
The first view we will add, is the view that renders our list of recent blog posts. For this, create the following file and folder structure:
/components/com_blog/views/posts/tmpl/default.php
Notice that the folder name "posts" is plural, and not "post", which is singular. This is part of the framework's Naming Conventions: Since we're creating a view that's going to display multiple blog posts, we use the plural form "posts". Later on we will set up the view that displays a single blog post, which will have a singular name, "post".
We don't have a list of blog posts to display just yet, so inside the newly created default.php just add the following line for now:
Hello World, and welcome to my blog!
Also in the Model-View-Controller article you learned that a controller loads a model. The default controller that will be created expects a model which expects a database table by default. As we don't have a database yet, we will bypass this behavior by extending from ComDefaultControllerResource instead. Please create the the following file and folder structure:
/components/com_blog/controllers/post.php
And then add the following line of code to the file:
<? class ComBlogControllerPost extends ComDefaultControllerResource {}
Now, try opening http://localhost/HelloWorld/index.php?option=com_blog&view=posts in your browser and see if our message reaches your screen. Which it should, if you have set up everything correctly so far.
What just happened?
As you may have noticed, we didn't create a view class at all. Nor did we create a controller (except bypassing the default one), or a model either. In the cases where the framework can't find a class that you're implying that you're using, in this case a posts controller, a posts model or a posts view, it will just fall back to classes provided by the framework and use them instead.
This is part of what we call Nooku Magic:
If you're not trying to accomplish anything out of the ordinary, Nooku Framework will often do the job for you. In other words: Don't add code until you're sure you really need it. More on this in the following parts of this tutorial.