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 4: Configuration 30<br />

Chapter 4<br />

Configuration<br />

<strong>Doctrine</strong> controls configuration of features and functionality using attributes. In this section<br />

we will discuss how to set and get attributes as well as an overview of what attributes exist<br />

for you to use to control <strong>Doctrine</strong> functionality.<br />

Levels of Configuration<br />

<strong>Doctrine</strong> has a three-level configuration structure. You can set configuration attributes at a<br />

global, connection and table level. If the same attribute is set on both lower level and upper<br />

level, the uppermost attribute will always be used. So for example if a user first sets default<br />

fetchmode in global level to <strong>Doctrine</strong>_Core::FETCH_BATCH and th<strong>en</strong> sets a table<br />

fetchmode to <strong>Doctrine</strong>_Core::FETCH_LAZY, the lazy fetching strategy will be used<br />

wh<strong>en</strong>ever the records of that table are being fetched.<br />

• Global level - The attributes set in global level will affect every connection and<br />

every table in each connection.<br />

• Connection level - The attributes set in connection level will take effect on each<br />

table in that connection.<br />

• Table level - The attributes set in table level will take effect only on that table.<br />

In the following example we set an attribute at the global level:<br />

Listing<br />

4-1<br />

// bootstrap.php<br />

// ...<br />

$manager->setAttribute(<strong>Doctrine</strong>_Core::ATTR_VALIDATE,<br />

<strong>Doctrine</strong>_Core::VALIDATE_ALL);<br />

In the next example above we override the global attribute on giv<strong>en</strong> connection:<br />

Listing<br />

4-2<br />

// bootstrap.php<br />

// ...<br />

$conn->setAttribute(<strong>Doctrine</strong>_Core::ATTR_VALIDATE,<br />

<strong>Doctrine</strong>_Core::VALIDATE_NONE);<br />

In the last example we override once again the connection level attribute in the table level:<br />

Listing<br />

4-3<br />

// bootstrap.php<br />

// ...<br />

$table = <strong>Doctrine</strong>_Core::getTable('User');<br />

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

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

Saved successfully!

Ooh no, something went wrong!