Chapter 13: Data Validation 212 The notnull constraint also acts as an application level validator. This means that if Doctrine validators are turned on, Doctrine will automatically check that specified columns do not contain null values when saved. If those columns happen to contain null values Doctrine_Validator_Exception is raised. Email The e-mail validator simply validates that the inputted value is indeed a valid e-mail address and that the MX records for the address domain resolve as a valid e-mail address. Listing 13-6 // models/User.php class User extends BaseUser { // ... public function setTableDefinition() { parent::setTableDefinition(); // ... } } $this->hasColumn('email', 'string', 255, array( 'email' => true ) ); Here is the same example in YAML format. You can read more about YAML in the YAML Schema Files (page 195) chapter: Listing 13-7 --- # schema.yml # ... User: columns: # ... email: type: string(255) email: true # ... Now when we try and create a user with an invalid email address it will not validate: Listing 13-8 // test.php // ... $user = new User(); $user->username = 'jwage'; $user->email = 'jonwage'; if ( ! $user->isValid()) { echo 'User is invalid!'; } ----------------- Brought to you by
Chapter 13: Data Validation 213 The above code will throw an exception because jonwage is not a valid e-mail address. Now we can take this even further and give a valid e-mail address format but an invalid domain name: // test.php Listing 13-9 // ... $user = new User(); $user->username = 'jwage'; $user->email = 'jonwage@somefakedomainiknowdoesntexist.com'; if ( ! $user->isValid()) { echo 'User is invalid!'; } Now the above code will still fail because the domain somefakedomainiknowdoesntexist.com does not exist and the php function checkdnsrr() 26 returned false. Not Blank The not blank validator is similar to the not null validator except that it will fail on empty strings or strings with white space. // models/User.php Listing 13-10 class User extends BaseUser { // ... public function setTableDefinition() { parent::setTableDefinition(); // ... } } $this->hasColumn('username', 'string', 255, array( 'notblank' => true ) ); Here is the same example in YAML format. You can read more about YAML in the YAML Schema Files (page 195) chapter: --- # schema.yml Listing 13-11 # ... User: columns: username: type: string(255) 26. http://www.php.net/checkdnsrr ----------------- Brought to you by
Doctrine ORM for PHP Guide to Doctr
Table of Contents iii Examples ....
Table of Contents v Sample Queries
Table of Contents vii Component Que
Table of Contents ix Inserting a No
Table of Contents xi Generating Mig
Chapter 1: Introduction 13 Chapter
Chapter 1: Introduction 15 layer de
Chapter 1: Introduction 17 Further
Chapter 2: Getting Started 19 Insta
Chapter 2: Getting Started 21 Downl
Chapter 2: Getting Started 23 In th
Chapter 3: Introduction to Connecti
Chapter 3: Introduction to Connecti
Chapter 3: Introduction to Connecti
Chapter 4: Configuration 31 $table-
Chapter 4: Configuration 33 backtic
Chapter 4: Configuration 35 class M
Chapter 4: Configuration 37 // boot
Chapter 5: Connections 39 Chapter 5
Chapter 5: Connections 41 $conn = D
Chapter 5: Connections 43 This is p
Chapter 6: Introduction to Models 4
Chapter 6: Introduction to Models 4
Chapter 6: Introduction to Models 4
Chapter 6: Introduction to Models 5
Chapter 7: Defining Models 53 Chapt
Chapter 7: Defining Models 55 } } /
Chapter 7: Defining Models 57 class
Chapter 7: Defining Models 59 Strin
Chapter 7: Defining Models 61 class
Chapter 7: Defining Models 63 class
Chapter 7: Defining Models 65 $this
Chapter 7: Defining Models 67 onUpd
Chapter 7: Defining Models 69 // te
Chapter 7: Defining Models 71 First
Chapter 7: Defining Models 73 } } $
Chapter 7: Defining Models 75 In ma
Chapter 7: Defining Models 77 Here
Chapter 7: Defining Models 79 class
Chapter 7: Defining Models 81 Here
Chapter 7: Defining Models 83 } } )
Chapter 7: Defining Models 85 --- #
Chapter 7: Defining Models 87 } { }
Chapter 7: Defining Models 89 } } )
Chapter 7: Defining Models 91 Some
Chapter 7: Defining Models 93 Now w
Chapter 7: Defining Models 95 # ...
Chapter 7: Defining Models 97 Concl
Chapter 8: Working with Models 99 $
Chapter 8: Working with Models 101
Chapter 8: Working with Models 103
Chapter 8: Working with Models 105
Chapter 8: Working with Models 107
Chapter 8: Working with Models 109
Chapter 8: Working with Models 111
Chapter 8: Working with Models 113
Chapter 8: Working with Models 115
Chapter 8: Working with Models 117
Chapter 8: Working with Models 119
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 9: DQL (Doctrine Query Lang
Chapter 16: Behaviors 263 ) [name]
Chapter 16: Behaviors 265 } public
Chapter 17: Searching 267 Chapter 1
Chapter 17: Searching 269 body LONG
Chapter 17: Searching 271 • Strip
Chapter 17: Searching 273 $ php tes
Chapter 17: Searching 275 // test.p
Chapter 18: Hierarchical Data 277 N
Chapter 18: Hierarchical Data 279 i
Chapter 18: Hierarchical Data 281 E
Chapter 18: Hierarchical Data 283 F
Chapter 19: Data Fixtures 285 Chapt
Chapter 19: Data Fixtures 287 class
Chapter 19: Data Fixtures 289 Resou
Chapter 19: Data Fixtures 291 --- #
Chapter 20: Database Abstraction La
Chapter 20: Database Abstraction La
Chapter 20: Database Abstraction La
Chapter 20: Database Abstraction La
Chapter 20: Database Abstraction La
Chapter 20: Database Abstraction La
Chapter 21: Transactions 305 log 43
Chapter 21: Transactions 307 try {
Chapter 22: Event Listeners 309 Cha
Chapter 22: Event Listeners 311 pub
Chapter 22: Event Listeners 313 pos
Chapter 22: Event Listeners 315 } {
Chapter 22: Event Listeners 317 */
Chapter 22: Event Listeners 319 FRO
Chapter 22: Event Listeners 321 Ski
Chapter 23: Caching 323 $cacheDrive
Chapter 23: Caching 325 // bootstra
Chapter 24: Migrations 327 Chapter
Chapter 24: Migrations 329 array('t
Chapter 24: Migrations 331 { } // .
Chapter 24: Migrations 333 $options
Chapter 24: Migrations 335 Up/Down
Chapter 24: Migrations 337 Now you
Chapter 25: Extensions 339 $ cd /pa
Chapter 26: Utilities 341 $pager->g
Chapter 26: Utilities 343 Currently
Chapter 26: Utilities 345 Template
Chapter 26: Utilities 347 Doctrine_
Chapter 26: Utilities 349 // Possib
Chapter 26: Utilities 351 // Genera
Chapter 26: Utilities 353 You can r
Chapter 26: Utilities 355 The above
Chapter 27: Unit Testing 357 $ cd /
Chapter 27: Unit Testing 359 } // .
Chapter 27: Unit Testing 361 Common
Chapter 28: Improving Performance 3
Chapter 28: Improving Performance 3
Chapter 28: Improving Performance 3
Chapter 29: Technology 369 Doctrine
Chapter 29: Technology 371 • Neve
Chapter 30: Exceptions and Warnings
Chapter 31: Real World Examples 375
Chapter 31: Real World Examples 377
Chapter 31: Real World Examples 379
Chapter 32: Coding Standards 381 Ch
Chapter 32: Coding Standards 383 Fu
Chapter 32: Coding Standards 385 $s
Chapter 32: Coding Standards 387 Fu