php - How do I validate multiple models with Yii? -
i using following code save , validate booking , bookingroom(link table) models, can validate 1 @ time. have had success in following saves , populates database, validation occurs in sequence.
$booking->save();
$bookingroom->save();
how validate , save multiple models?
you should call validate() method model, example bellow:
// populate input data $a , $b $a->attributes=$_post['a']; $b->attributes=$_post['b']; // validate both $a , $b $valid=$a->validate(); $valid=$b->validate() && $valid; if($valid) { // use false parameter disable validation $a->save(false); $b->save(false); // ...redirect page }
see link more information.
Comments
Post a Comment