Working with objects - Component overview - Record - Creating new records.php 626 Bytes
Newer Older
doctrine's avatar
doctrine committed
1
There are couple of ways for creating new records. Propably the easiest is using
2
native php new -operator. The other ways are calling Doctrine_Table::create() or Doctrine_Connection::create().
doctrine's avatar
doctrine committed
3
The last two exists only for backward compatibility. The recommended way of creating new objects is the new operator.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

<code type="php">
$user = $conn->create("User");

// alternative way:

$table = $conn->getTable("User");

$user = $table->create();

// the simpliest way:

$user = new User();


// records support array access
$user["name"] = "John Locke";

// save user into database
$user->save();
</code>