[eluser]Alface[/eluser]
[quote author="OverZealous" date="1256955791"]
@Alface
Edit: removed rude comment - sorry, I just got up.
Validation is automatically run when you call
save. This has nothing to do with the transaction status.
Every time you call save(), you must check the result, for
every object.
If validation fails, the save will not go through. The whole point of using transactions is that you can safely save multiple items, and if the last one fails, the DB will rollback all of the changes. In fact, you
have to do it this way, because DMZ expects "existing" items to exist in the database, even ones
just saved.
Finally, the transaction status is only useful in explaining when the database
itself has been unable to save. If the failure was in the validation of your DMZ model, the transaction status will be TRUE, because no save query was processed.
So, again, your code needs to look like this:
Code:
if($object->save()) {
if($object2->save($object1)) {
// etc
} else {
// etc
}
} else {
// fail
}
or like this
Code:
$success = $object->save();
$success = $success && $object2->save();
if(!$success) {
// process $object->error and $object2->error
}
[/quote]
By default DMZ came with a form template than handle the list of erros like this:
Code:
<? if( ! empty($object->error->all)): ?>
<div class="error">
<p>There was an error saving the form.</p>
<ul><? foreach($object->error->all as $k => $err): ?>
<li><?= $err ?></li>
<? endforeach; ?>
</ul>
</div>
<? endif; ?>
And when I call it form the htmlform extension
Code:
<?=$va->render_form($campos,$url)?>
The question is, how can I unificate the list of erros of 2 objects?
Code:
$success = $object->save();
$success = $success && $object2->save();
if(!$success) {
// process $object->error and $object2->error
// if I repeat render_form(), I will have 2 forms..
// and I would like to reuse the same form template
// $object->render_form($fields,$url)
}