The Form tutorial - the beginning
- Posted by dlib on March 21st, 2008 filed in Form tutorial, Tutorials, Validation
Ok, in my previous post I detailed on what this tutorial should cover. Now it’s time for the actual tutorial. Before I illustrate the usage of several approaches towards forms we have to deal with some common things. The form we’re going to create deals with food preferences so we’ll call the database table we’re going to use ‘preferences’.
Table definition, add to your db
CREATE TABLE IF NOT EXISTS `preferences` ( `id` smallint(6) NOT NULL AUTO_INCREMENT, `name` varchar(50) collate utf8_unicode_ci NOT NULL, `email` varchar(255) collate utf8_unicode_ci NOT NULL, `preference` varchar(255) collate utf8_unicode_ci NOT NULL, `comment` tinytext collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
Every table needs a model and since we’re using ORM, the model will utilize ORM.
models/preference.php
class Preference_Model extends ORM {}
It’s as simple as models can get. I might add to it later on for the Formation module.
Now we need a controller with two methods, one for adding records, one for editing.
controllers/preferences.php
class Preferences_Controller extends Controller{ public function insert() {} public function update($id){} }
This is what all approaches to forms have in common.
I will deal with the update($id) in later posts. I’ve dedicated category to all posts concerning themselves with this tutorial.
The tutorials:
May 24th, 2008 at 4:16 pm
The links don’t work anymore.
May 24th, 2008 at 10:49 pm
It’s on my todo list. You can replace the hostname with learn.kohanaphp.com and you’ll get to the right url though.
August 13th, 2008 at 9:39 pm
[...] you’ve set up and the model as seen in a previous post we can now begin with building a form using [...]
October 15th, 2008 at 8:47 am
No offense, but “it’s on my todo list”?? How hard is it to update a link…and that was in May. That’s a long todo list.
I’m new to kohana, and while I’m finding it interesting to work with, I suspect the lack of good documentation must be turning potential users away.
October 15th, 2008 at 1:25 pm
I’m sorry,I’m terribly busy with a lot of stuff and Kohana has been off the radar for a while. If you change the domain of the links to the current domain ‘learn.kohanaphp.com’ it should work.