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