2008年9月25日星期四

[fw-mvc] Validating/writing data

Hi all,

because of our discussion about "where to put my code" I have found
DAO pattern what I am going to use. I would like to ask you about this
pattern resp. about its proper implementation within ZF.

I have for all application entities own models which cooperates with
proper DAO. DA objects, eg. for Db Tables as data storage, are
extended from Zend_Db_Table_Abstract.

I am looking for how to validate data and then write changes into
database table (yes, I do validation in the model). Eg. this is model
for entity User and we need to insert new account data:

Option A
========
if($this->_getDao()->validateInsert($data)){
$userId = $this->_getDao()->insert($data);
}else{
$messages = $this->_getDao()->getMessages();
}

Option B
========
$actionObject = $this->_getDao()->getInsert($data);

if($actionObject->isValid()){
$userId = $actionObject->execute();
}else{
$messages = $actionObject->getMessages();
}

Option C
========
$userId = $this->_getDao()->insert($data);

if($userId == 0){
$messages = $this->_getDao()->getMessages();
}

What do you think about these three options? What is the best? What is
your best practise when you need validate and then write changes into
some datasource?

Thanks, J.

没有评论: