Scaffolding a bookmarks manager

A tutorial for the Cake PHP framework

What you will learn

How to create a working bookmarks manager in less than 5 minutes by using Cake's scaffolding abilities.

What you will need

An installation of Cake and a working database. Visit the Cake Wiki for an installation tutorial.

WebMonkey covered a similar topic for Ruby on Rails. I did this version for comparison.

1. Create the database table

Create the database table structure to hold your bookmarks.

CREATE TABLE bookmarks (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
url VARCHAR(255) NOT NULL,
created DATETIME,
modified DATETIME,
PRIMARY KEY (id) 
);

2. Create a Model file

Create a file called bookmark.php and put it in the /app/models folder. Copy and paste the code below into your file. Save it.

<?php
class Bookmark extends AppModel
{
	var $name = 'Bookmark';
}
?>

3. Create a Controller file

Create a file called bookmarks_controller.php in the /app/controllers folder. Copy and paste the code below into your file. Save it.

<?php
class BookmarksController extends AppController
{
	var $name = 'Bookmarks';
	var $scaffold;
}
?>

By declaring the $scaffold variable Cake automatically build our bookmarks manager for us.

4. Finished

Visit www.example.com/bookmarks. You now have a fully working bookmark management application.

Want more?

Try the simple blog tutorial on the Cake Wiki.

Comments and feedback

Please e-mail graham at grahambird dot co dot uk