SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    The Omnipresent [ArcanE]'s Avatar
    Join Date
    Mar 2005
    Location
    Belgium
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DAO pattern, where to validate?

    I'm thinking of implementing the DAO and VO pattern into my webapplications to serve as my data layer.

    That made me think, i need to implement some sort of data validation to prevent the data in my database loosing it's integrity.

    Where would i perform this sort of validation? In the DAO or in the VO with setters? Or perhaps completely separate from the DAO and VO in my business layer before i instantiate my DAO and VO objects?
    Webdevelopment : Skyrocket Concepts Inventis Web Architects
    Ain't got time for the future or the past.
    Live for the moment, make it last.

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if this is the best way, but my DAO extend a base class which have a save/update method. The save/method calls my Validation class.. so it kind of looks like this

    PHP Code:

     
    //My Controller

     
    class Controller {
       public 
    method createClient($values) {
         
    $c = new Client();
         
    $c->save($values);  
       }
     }

     class 
    Client extends DAO {
    public 
    $props = array('ID'=>array('max_length'=>'10','type'=>'int','required'=>'','default'=>'','null'=>'NO'),
    'f_name'=>array('max_length'=>'45','type'=>'varchar','required'=>true,'default'=>'','null'=>'NO'),  'l_name'=>array('max_length'=>'45','type'=>'varchar','required'=>'','default'=>'','null'=>'NO'),
    'email'=>array('max_length'=>'45','type'=>'varchar','required'=>'','default'=>'','null'=>'NO'),  'userID'=>array('max_length'=>'45','type'=>'varchar','required'=>'','default'=>'','null'=>'NO'),
    'propCount'=>5);

        
    //Extra logic

     
    }

     class 
    DAO {
       public 
    method save($values) {
          try{
            
    $this->_validate$values$this->props );
          } catch (
    Exception $e) {
             throw new 
    Exception($e->getMessage());
          }
       }
       protected function 
    _validate($value$properties) {
          
    $v = new Validation();
          try {
            
    $v->validate($values$properties);
          } catch (
    Exception $e) {
            throw new 
    Exception($e->getMessage());
          }
       }
     }

     
    $c = new Controller();
     
    $c->createClient($clientArray); 
    Something like that, I'm sure I forgot something.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •