Before We Start

It is a good idea to make sure you have obyx available on a webserver, configured to have access to a database. You will need to be able to add files and run them also. It's a good idea to use a self-contained subdirectory for this project - but not necessary!

Onto the tutorial - First of all, we must construct an idea of what our application is going to be. In the business world, we also need to show that it will have some business value, but here we don't need to worry about that so much.

It is best to use the maxim "start small" - have the basic system, and then later on add the wonderful bits and pieces that makes your DVD-Video library software the envy of all your friends!

Using MVC - Obyx lends itself very well to using an MVC (Model-View-Controller) pattern, and for this project, we will do that. The views are going to be written in XHTML, the model will be held in MySQL and the controllers will be written in Obyx.

So let's start off with a minimal DVD-Video library web application. We will need to list DVDs, and view/edit individual DVDs also. Lists can be ordered in different ways, including search results, so we will keep the list methods quite flexible from the start, so therefore we have two basic views for the user: A list view, and a details view. When we open up the application, we could start with either (or use the last view visited) - but let's choose the list view as the default / initial view for the library.

Now, before we get carried away with all of these views, we also need to think about our model: What it is we are actually interested in; which in this case is a DVD library. We will be using SQL to store the library, so we will be looking at a very simple object structure to start off with - just a single SQL table of DVD records. Later on we will need to work out just what sort of details we want to hold against each DVD, but first of all we probably want to start off with defining the absolute minimum which uniquely identifies a DVD. Fortunately, DVDs are covered by the ean13 system - so we can use the 13 digit ean13 number for all our DVDs. This will deal with most modern DVDs - and it should be easy enough for us to extend that system to cover the exceptions. Even better, if we have a barcode reader, the normal barcode on a DVD is the encoded ean13 - and we could extend our library to other items (such as books) that also use an ean13 with very little additional effort.

But we aren't machines - so let's also add a title to the record.

Here is the mysql table creation. We have added a default value to the title, which is useful if we are going to use the title for things like links. Also, the ean13 is a primary key - this will prevent any item from being entered in twice. We have also added in a few records just to make it easy to see what's going on. (It's a good idea to make sure that your default encoding is utf-8. UTF-8 deals with nearly every character there is (ok, so not klingon), and will eliminate any problems with odd characters such as TM, or curly quotes).

Because we may want to extend our model later, the table is called 'ean13item', so we can later add other things in our library which have ean13 numbers, rather than just dvd's.

CREATE TABLE ean13item (
  ean13 char(13) NOT NULL,
  title char(128) NOT NULL default 'unrecorded title',
  PRIMARY KEY (ean13)

insert into ean13item set ean13=5060034578277,title='The Deer Hunter';
insert into ean13item set ean13=5035673005323,title='Rashomon';
insert into ean13item set ean13=5017188883214,title='Pulp Fiction';

| ean13         | title           |
| 5060034578277 | The Deer Hunter | 
| 5035673005323 | Rashomon        | 
| 5017188883214 | Pulp Fiction    | 

We have covered the view, and the model - so now we need to think about how we wish to manipulate our information - the control. The three key statements in SQL give us a good idea about we will need to be doing for our library:

select - we will need to list and view our DVD records.
update - we will need to edit our DVD records.
insert - we will need to add to our DVD library.

Let's not worry about deletion just yet!

So from the front (list) screen of the application, we need to be able to view, edit, or add to the library. Let's decide to add one DVD at a time as our basic process - this means that we have three separate reasons to visit the details page: To view or edit an existing DVD's details, or to add a new DVD with a new set of details.

The NEW link is not tied to a specific existing record, of course, so we need to treat it a bit differently from the update/view links. Also, we could skip having to decide about editing/viewing from the front page - and have that as an option from the details page. This reduces the complexity a tiny bit.

Let's now generate the list view of DVD library. First of all, it's going to be just purely functional - but you can use design skills later to make it appear excellent!

We are going to use XHTML Strict - with a declared namespace on our root element. We will just add comments as placeholders for the time being. We can use ids on our main structural elements so that we have easy accessors to these points. This makes the markup more resistant to redesigns!

We also need to do the actual list itself. So, in most cases it will be an ordered list, with each list item representing a dvd-video, but also with a link to the details screen. We could use apache to our advantage here, and just use the ean13 as a link to the details (or item) page for that link.

	<li><a href="dvditem.obyx?5060034578277">The Deer Hunter</a></li>
	<li><a href="dvditem.obyx?5035673005323">Rashomon</a></li>

Both ol and ul are not allowed to be empty in XHTML, so we need to add a hidden li to keep the xhtml valid, as an empty list is possible in our model! So we want something like the following.

	<li style="display:none;" ><!-- hidden --></li>

But actually, we could use the dvditem.obyx with no value for when we want to create a new dvd in our library, so let's do that instead.

Click the link below to go to the next part of our tutorial

Last Modified: Thu, 15 Jan 2015