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 213<br />

The above code will throw an exception because jonwage is not a valid e-mail address. Now<br />

we can take this ev<strong>en</strong> further and give a valid e-mail address format but an invalid domain<br />

name:<br />

// test.php<br />

Listing<br />

13-9<br />

// ...<br />

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

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

$user->email = 'jonwage@somefakedomainiknowdoesntexist.com';<br />

if ( ! $user->isValid()) {<br />

echo 'User is invalid!';<br />

}<br />

Now the above code will still fail because the domain<br />

somefakedomainiknowdoesntexist.com does not exist and the php function<br />

checkdnsrr() 26 returned false.<br />

Not Blank<br />

The not blank validator is similar to the not null validator except that it will fail on empty<br />

strings or strings with white space.<br />

// models/User.php<br />

Listing<br />

13-10<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('username', 'string', 255, array(<br />

'notblank' => true<br />

)<br />

);<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 />

Listing<br />

13-11<br />

# ...<br />

User:<br />

columns:<br />

username:<br />

type: string(255)<br />

26. http://www.php.net/checkdnsrr<br />

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

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

Saved successfully!

Ooh no, something went wrong!