10.04.2018 Views

Doctrine_manual-1-2-en

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13: Data Validation 224<br />

Listing<br />

13-43<br />

---<br />

# schema.yml<br />

# ...<br />

User:<br />

columns:<br />

# ...<br />

cc_number:<br />

type: integer(16)<br />

creditcard: true<br />

# ...<br />

Read Only<br />

The read only validator will fail validation if you modify a column that has the readonly<br />

validator <strong>en</strong>abled on it.<br />

Listing<br />

13-44<br />

// models/User.php<br />

class User ext<strong>en</strong>ds BaseUser<br />

{<br />

// ...<br />

public function setTableDefinition()<br />

{<br />

par<strong>en</strong>t::setTableDefinition();<br />

// ...<br />

}<br />

}<br />

$this->hasColumn('readonly_value', 'string', 255, array(<br />

'readonly' => true<br />

)<br />

);<br />

Listing<br />

13-45<br />

Here is the same example in YAML format. You can read more about YAML in the YAML<br />

Schema Files (page 195) chapter:<br />

---<br />

# schema.yml<br />

# ...<br />

User:<br />

columns:<br />

# ...<br />

readonly_value:<br />

type: integer(16)<br />

readonly: true<br />

# ...<br />

Now if I ever try and modify the column named readonly_value from a User object<br />

instance, validation will fail.<br />

Unsigned<br />

The unsigned validator checks that the giv<strong>en</strong> integer value is unsigned.<br />

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

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

Saved successfully!

Ooh no, something went wrong!