10.04.2018 Views

Doctrine_manual-1-2-en

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10: Compon<strong>en</strong>t Overview 164<br />

$conn = <strong>Doctrine</strong>_Manager::connection();<br />

$user1 = new User();<br />

$user1->username = 'Jack';<br />

$user2 = new User();<br />

$user2->username = 'jwage';<br />

$conn->flush();<br />

Calling <strong>Doctrine</strong>_Connection::flush() will save all unsaved record instances for that<br />

connection. You could of course optionally call save() on each record instance and it would<br />

be the same thing.<br />

Listing<br />

10-6<br />

// test.php<br />

// ...<br />

$user1->save();<br />

$user2->save();<br />

Table<br />

<strong>Doctrine</strong>_Table holds the schema information specified by the giv<strong>en</strong> compon<strong>en</strong>t (record).<br />

For example if you have a User class that ext<strong>en</strong>ds <strong>Doctrine</strong>_Record, each schema<br />

definition call gets delegated to a unique table object that holds the information for later use.<br />

Each <strong>Doctrine</strong>_Table is registered by <strong>Doctrine</strong>_Connection. You can retrieve the table<br />

object for each compon<strong>en</strong>t easily which is demonstrated right below.<br />

For example, lets say we want to retrieve the table object for the User class. We can do this<br />

by simply giving User as the first argum<strong>en</strong>t for the <strong>Doctrine</strong>_Core::getTable() method.<br />

Getting a Table Object<br />

In order to get table object for specified record just call <strong>Doctrine</strong>_Record::getTable().<br />

Listing<br />

10-7<br />

// test.php<br />

// ...<br />

$accountTable = <strong>Doctrine</strong>_Core::getTable('Account');<br />

Getting Column Information<br />

You can retrieve the column definitions set in <strong>Doctrine</strong>_Record by using the appropriate<br />

<strong>Doctrine</strong>_Table methods. If you need all information of all columns you can simply use:<br />

Listing<br />

10-8<br />

// test.php<br />

// ...<br />

$columns = $accountTable->getColumns();<br />

$columns = $accountTable->getColumns();<br />

foreach ($columns as $column)<br />

{<br />

print_r($column);<br />

}<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!