Day 2 - First Symfony App
February 10th, 2008
Well, from yesterday, we have web hosting, PEAR, and symfony installed.
Since data is the whole point of any application, I want to start this project with the Model part of MVC. Symfony uses YAML to define what the data will look like. One of the neat points of this framework is symfony’s ability to build the database from this YAML “sketch”.
For this DVD database, I would like to store the DVD type, title, and the leading actors/actresses. (Yes, I’m being a bit overly optimistic about HD disks making their way into the library anytime soon!) So, in my head, I’m going to need a table for type, another for titles, and another for actors.
In the type table, I want a primary key (just a serial number) and a bit of text describing the type. In SQL-eese, I would do this like this:
create database dvddatabase;
create table type (type_id integer primary key, type varchar(15));
insert into type values ("1", "DVD");
insert into type values ("2", "HD-DVD");
insert into type values ("3", "Blue-Ray");
But, alas, I’m not - this needs to be implemented in YAML. So, off to YAML land…
dvd:
type:
type_id: ~
type: varchar(15)
The tilde (”~”) is used to tell symfony to “figure it out”. (so, does that mean I could make them all ~? (laugh.)
Need a a table for DVD Titles:
id: ~
dvdname: varchar(128)
type: ~
One for who starred in the film:
starring:
starring_id: ~
actor: varchar(50)
Finally, one to link the id and the starring tables together:
id_starring:
id_starring_id: ~
id_id: ~
starring_id: ~
So, the completed YAML file looks like this:
propel:
dvd:
type:
type_id: ~
type_name: varchar(15)
id: ~
id_id: ~
dvdname: varchar(128)
type: ~
created_date: ~
starring:
starring_id: ~
actor: varchar(50)
id_starring:
id_starring_id: ~
id_id: ~
starring_id: ~
This setup is quite odd to me. I tend to think of data in terms of one-to-many relationships (like the table above), it seems to me that some sort of declaration is needed.
Just for fun, since the type table will be rather short, I think I’ll try directly inputting the starting data:
propel:
dvd:
type:
type_id: ~
type_name: varchar(15)
- DVD
- HD-DVD
- Blu-Ray
id: ~
id_id: ~
dvdname: varchar(128)
type: ~
created_date: ~
starring:
starring_id: ~
actor: varchar(50)
id_starring:
id_starring_id: ~
id_id: ~
starring_id: ~
So, save all that to config/schema.yml, then (from the project directory) symfony propel-build-model, and experience our first problem. Symfony says schema.yml can contain only one DB entry. I’m assuming it’s referring to the 3 rows I was trying to add in one table. Ok, I can play this game, and remove the HD entries, then rerun the propel-build-model.
We now have a DB schema, which symfony recognizes and thinks it knows how to handle.
Boldly going… to symfony propel-build-all, looks good, right until the end. Looks like there is a problem connecting to mysql through a socket. It’s late, I’ve got traveling to do tomorrow, so I’m going to sign off for now.
Leave a Reply
You must be logged in to post a comment.