Archive for the Framework Category
Getting started with foreign keys
An often asked question on the Nooku Framework mailing list is how to deal with relations in databases. Nooku Framework doesn’t support relations out of the box yet, but fortunately the InnoDB engine in MySQL does!
There are three important rules that must be met in order to create relations:
- Both tables must be InnoDB tables and must not be TEMPORARY tables.
- Keys must have similar internal data types.
- Both foreign and referenced keys need to be indexed.
A basic example
Let’s see the basics through an example:
Assume that we have an articles table with two columns: article_id and title. We have an authors table as well with the columns: author_id and name. Here is the SQL code for the tables:
CREATE TABLE IF NOT EXISTS `articles` ( `article_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `title` VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY (`article_id`) ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; CREATE TABLE IF NOT EXISTS `authors` ( `author_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY (`author_id`) ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
We want to assign authors to articles. An author can belong to more than one articles, and an article can belong to more than one authors. So this is a many-to-many relation. That’s why we need a relation table too, which has article_id and author_id columns:
CREATE TABLE IF NOT EXISTS `articles_authors` ( `article_id` INT UNSIGNED NOT NULL, `author_id` INT UNSIGNED NOT NULL, FOREIGN KEY (`article_id`) REFERENCES `articles`(`article_id`) ON DELETE CASCADE, FOREIGN KEY (`author_id`) REFERENCES `authors`(`author_id`) ON DELETE RESTRICT ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
As you can see, we specified the foreign keys with CASCADE and RESTRICT options. Let’s try to delete an article. Notice that relations in the articles_authors table are deleted with it automatically. Now let’s try to remove an author. If the author is referenced in the relation table, then MySQL refuses to delete it. This ensures referential integrity.
Keeping referential integrity
By using InnoDB, you can prevent accidental removal of referenced rows. Other than its roboust data management features, it has usability advantages too. For example some of the database management tools support foreign keys too. For example in Sequel Pro, an arrow is displayed next to the column’s value, and it takes you to the referenced row when you click on it. This little feature can be useful many times.
InnoDB has become the default engine in MySQL 5.5 and has many features over MyISAM. I am highly recommending every developer to consider using it in their applications.
This was just a basic introduction to foreign keys, it is capable of much more! If you are interested, visit the MySQL Reference Manual.
The magic of primary and unique keys
It’s all in the schema
If primary and unique keys are properly defined in the database schema, it is possible to retrieve an item without writing any line of code. In com_harbour’s boats table, harbour_boat_id is a primary key, and slug is a unique key. It is possible to get the same boat by using any of these keys:
index.php?option=com_harbour&view=boat&id=4 index.php?option=com_harbour&view=boat&slug=queen-mary-2
There is an important thing to note here. If an identity column exists (an auto increment key), the name “id” is used for it in the framework. So for example the column harbour_boat_id is accessed as $boat->id.
A look under the hood
Let’s look deep into how this works under the hood. In the first step, the database class fetches column and index information from the database. In the second step, the model requests the parsed information from the table class and creates a state for each key.
Form validation with Nooku Framework
Responsive validation feedback on forms is no longer a “nice to have” feature in modern web apps, it’s a standard that users have come to expect to be there.
In Nooku Framework Alpha 3, we added a new API that loads the forms validation library in MooTools More for you. And we implemented it in Nooku Server Alpha 3 to improve the usability of refactored components.
Today I’ll show you how easy it is to get started by simply adding CSS classes to your form inputs. Then I’ll show you how easy it is to create your own input validators for when you need to validate something custom.
The State of Nooku 2011
Past weekend, the Nooku Team was at the Dutch Joomladays, as both sponsors and speakers. The event sold completely out. Two days with 200 attendees each, that’s a lot of interesting people to meet. Very positive vibe and and superb organisation, one of the best Joomladays I ever attended. A big congrats to everyone who helped to make this happen.
We have a tradition of showing something new each year at the Dutch Joomladays, so Tom and myself were very proud to officially announce our Nooku Platform and present our second State of Nooku.
Nooku Framework’s 3rd Birthday!
Just over three years ago, on 12 February 2008, we made the first commit to our beloved Nooku Framework. Today, Nooku Framework drastically speeds up the creation and maintenance of Joomla extensions while eliminating repetitive coding and adding power, flexibility and fun. Finally, you can focus on what matters most: your extension’s business logic and user experience.
Definition: “to nookify” (verb) : Collaborating to make code reusable, flexible and magical. Often leads to reduction of 60-80% in code.
Introducing Nooku Platform
On the 4th of February 2011, we attended the first ever Joomlanight in Stockholm, Sweden. The topic of this event was “Joomla: At The Edge Of Innovation” and hosted three talks:
- “The Road Ahead for Joomla!” by Ryan Ozimek
- “Molajo Joomla! 1.6 Distribution” by Marco Barbosa
- “Nooku – Evolving and Innovating Joomla!” by our own Johan Janssens
Johan introduced the Nooku Platform, vision, strategy and roadmap:
- Nooku Framework, rapid extension development framework
- Nooku Server, multi-site and multi-lingual distribution of Joomla
- Nooku Community, innovative and open source community
The event was broadcasted live on the inter-tubes, thanks to Martin Blodau. If you missed it, sit back and enjoy Johan’s talk. We also made the presentation available here.
Read the rest of this entry »
Split Views using Nooku Framework
A month ago Martin asked a very interesting question on Twitter.
Possible to load a detail view & it’s related list view besides each other in the tab of a third view with the “H” of HMVC?
Short answer, yes offcourse ! Luckily our blog doesn’t have a 140 char limit so I can also show you how. In this tutorial I will explain:
- How to create a Ajaxed Split View.
- How to render that Split View from a module.
We will use the overlays we learned about in my previous blog post, and apply this to create the Split View.
Read the rest of this entry »
AJAX Widgets with Nooku Framework
We have been claiming for quite a while now that Nooku Framework helps you to write less code. A lot less! So time to put our money where our mouth is and show you a little example.
Today’s topic: Building an AJAX widget with just a few lines of code, actually just one line. We will be using a new simple technique called overlays. You don’t believe me? Watch and learn!
Read the rest of this entry »
Nooku Community rocking on
Just a little while ago we passed the 2500 commits mark in our Nooku Framework SVN. With all the work being done this little milestone almost slipped under the radar. Time for a little celebration!
Some facts. When we made the Nooku Framework codebase available on Sourceforge a little over a year ago the commit counter was at 1218. Today with all spaces combined we are nearing 3250 commits, that’s 2000 commits in one year. Amazing !
Nooku is slowly earning it’s spot with the big boys as you can see from the graph (taken from Ohloh) below. Not bad huh !
Read the rest of this entry »
Nooku Framework a CCK for developers
A year ago Steve Burge from Alledia wrote a blog post titled : Joomla Goes CCKrazy taking a closer look at the CCK explosion in the Joomla ecosystem. In his post Steve defines a CCK as :
- any extension which allows to move beyond the text and title options provided by Joomla’s com_content, and choose your own fields and options.
- any extension which also moved beyond the section/category hierarchy of Joomla 1.5 and 1.5.
Today the Joomla extensions site counts not less then 10 GPL licensed CCK solutions. All of which add advanced content management capabilities to Joomla. In a sense, each of the CCK solutions are mini CMS systems wrapped inside a Joomla extension.
Are CCK’s the answer to innovating Joomla ? I don’t believe so. One of the reasons I choose Mambo for my first web project back in the days was because it was easy to use and easy to extend. As a user I could set it up in 5 min, just running through the installer, and as a developer I could extend it in 5 min, just looking at the code.
Nooku Extension Showcase Video
More and more Joomla developers are starting to use Nooku Framework for building powerful, extendible and secure Joomla extensions. The first generation of extensions is in beta and more extensions are being worked.
Just like the Joomla 1.5 framework caused a wave of innovative extensions, we believe Nooku Framework is going to cause a shift: It changes how you create and use extensions, how extensions work with each other or with external data, and how you customize extensions.
At J! and Beyond 2010 we, together with some of our Nooku Community Contributors and Partners showed some of the promising Nooku-powered extensions that are being built right now. Check out the video and take a sneak peek into Joomla’s future !




