2 insert related / Help Please!
I have to store() if($x→store()
-
Message #559
i need to catch somehow the validation part of store.
Eu12/29/09 03:20:05 -
-
Message #560
You can validate both models before storing:
try { $x->validate(); $y->validate(); # Everything is ok, so store the models $x->store(); $y->store(); } catch ( fValidationException $e ) { // Handle Exception }
michfrm12/29/09 03:46:05 -
-
Message #561
store method contain built in validate method. so store came after populate, so what is the point of your x and y validation?
Eu12/29/09 04:56:41 -
-
Message #562
validate() does the same than the validation of store(). If you call validate() of both models before storing them you can prevent the case that model $x could be saved but $y not.
michfrm12/29/09 05:02:03 -
-
Message #563
i see now what your point you say to call validate twice once myself and after with store, i think it can work like this. now a i must to erase foreign key, first i try with foregn key but seems that florish have trouble with populate related and one to many relationship, you try this functionality?i want to know if it is work for someone. anyway tank you very much for your help and ideas.
Eu12/29/09 11:42:12
-
-
-
-
Message #570
If you pass TRUE to fActiveRecord::validate(), you get an array of errors back. You can do that for both records, merge the arrays, and then use the custom fValidationException::__construct() method to create a standard validation exception from a short intro plus the array of validation messages.
wbond12/29/09 15:22:33 -
-
Message #572
i don't know very well how try catching work in this example, can you provide me a short example how to do that you say earlier?
my cood looks like this:
if (isset($adauga_hotel)) { try { $validare = array(); $hotel_nou = new Hoteluri(); $last_hotel_id = Hoteluri::ultimulHotelIntrodus(); // cauta ultimul id din hotel ptr asigna valoarea camerei urmatorului hotel itnrodus foreach($last_hotel_id as $id) { $last_id = $id->getIdHotel(); } $last_id = $last_id + 1; $hotel_nou->populate(); $hotel_nou->setIdHotel($last_id); $hotel_nou->setFacilitatiHotel((!empty($_POST['facilitati'])) ? "" . implode($_POST['facilitati'], ',') . "" : ""); $hotel_nou->setServiciiHotel((!empty($_POST['servicii'])) ? "" . implode($_POST['servicii'], ',') . "" : ""); $validare_hotel = $hotel_nou->validate(TRUE); foreach($_POST['camera'] as $k => $l) { // multiple rooms pentru acelasi hotel $rooms{$k} = new Room(); $rooms{$k}->populate(); $rooms{$k}->setCamera($_POST['camera'][$k]); $rooms{$k}->setPret($_POST['pret'][$k]); $rooms{$k}->setMoneda($_POST['moneda'][$k]); $rooms{$k}->setIdHotel($last_id); $validare_camera = $rooms{$k}->validate(TRUE); $rooms{$k}->store(); } if ($hotel_nou->store()) { $xtpl->assign('SUCCES_HOTEL_NOU', '<div class="validation_succes">' . $translator->translate('Succes', '', $lg) . '</div>'); // upload poster $redenumire = fCryptography::randomString(10); $handle = new Upload($_FILES['poster']); if ($handle->uploaded) { $handle->file_new_name_body = $redenumire; $handle->image_convert = 'jpg'; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 800; $handle->Process($dir_h); $handle->file_new_name_body = $redenumire; $handle->image_convert = 'jpg'; $handle->image_resize = true; $handle->image_ratio_crop = true; $handle->image_y = 120; $handle->image_x = 160; $handle->image_resize = true; $handle->process($dir_thumbs_h); if ($handle->processed) { // $hotel_nou->setMedia(substr_replace($fisiere_uploadate ,"",-1)); echo 'OK'; } else { echo 'Error: ' . $handle->error; } } else { echo 'Error: ' . $handle->error; } unset($handle); // upload poze $files = array(); foreach($_FILES['media'] as $k => $l) { foreach($l as $i => $v) { if (!array_key_exists($i, $files)) $files[$i] = array(); $files[$i][$k] = $v; } } foreach($files as $file) { $redenumire = fCryptography::randomString(10); $handle = new Upload($file); if ($handle->uploaded) { $handle->file_new_name_body = $redenumire; $handle->image_convert = 'jpg'; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 800; $handle->Process($dir_h); $handle->file_new_name_body = $redenumire; $handle->image_convert = 'jpg'; $handle->image_resize = true; $handle->image_ratio_crop = true; $handle->image_y = 120; $handle->image_x = 160; $handle->image_resize = true; $handle->process($dir_thumbs_h); if ($handle->processed) { // $hotel_nou->setMedia(substr_replace($fisiere_uploadate ,"",-1)); echo 'OK'; } else { echo 'Error: ' . $handle->error; } } else { echo 'Error: ' . $handle->error; } unset($handle); } } } catch(fValidationException $e) { $validare = array_merge($validare_hotel,$validare_camera); $xtpl->assign('ERROR_HOTEL_NOU', $e->printMessage()); } } }
Eu12/30/09 06:13:41
-
-
