1
0
mirror of synced 2025-01-18 06:21:40 +03:00

more docs, hopefully my last commit tonight...

This commit is contained in:
pookey 2007-05-31 20:42:35 +00:00
parent 9187dbed0e
commit 148fc615c0

View File

@ -206,6 +206,44 @@
url="http://www.martinfowler.com/eaaCatalog/activeRecord.html">Active
Record pattern</ulink>
</para>
<para>
Doctrine auto-creates database tables and always adds a primary key
column named 'id' to tables that doesn't have any primary keys
specified. Only thing you need to for creating database tables is
defining a class which extends Doctrine_Record and setting a
setTableDefinition method with hasColumn() method calls.
</para>
<para>
An short example:
</para>
<para>
We want to create a database table called 'user' with columns
id(primary key), name, username, password and created. Provided that
you have already installed Doctrine these few lines of code are all you
need:
</para>
<programlisting role="php"><![CDATA[
<?php
require_once('lib/Doctrine.php');
spl_autoload_register(array('Doctrine', 'autoload'));
class User extends Doctrine_Record {
public function setTableDefinition() {
// set 'user' table columns, note that
// id column is always auto-created
$this->hasColumn('name','string',30);
$this->hasColumn('username','string',20);
$this->hasColumn('password','string',16);
$this->hasColumn('created','integer',11);
}
}
?>]]></programlisting>
<para>
We now have a user model that supports basic CRUD opperations!
</para>
</sect1>
</chapter>