anonīms Posted April 30, 2013 Report Share Posted April 30, 2013 (edited) mega super kruts jautājums, tīri intereses pēc. if($message = $leagueClass->validatedata($collected,$myteam) !== false) { print $message; } else { //daram darbu } ideja ir tāda, ka iekšs validate fjas ir $error = false; un tālāk jau šis errors tiek aizvietots ar error messedžu, ja tas kkur būs nepieciešams. protams es varu pirms tam nodefinēt, bet tā ir viena fakin rindiņa par daudz un man uz cietā vairs nav vieta ;[ $validated = $leagueClass->validatedata($collected,$myteam); if($validated != false) { print $validated; //error message } else { // daram darbu } bet šis ir vairak intereses pēc Edited April 30, 2013 by anonīms Quote Link to comment Share on other sites More sharing options...
rpr Posted April 30, 2013 Report Share Posted April 30, 2013 Nevar vienkārši? if($message = $leagueClass->validatedata($collected,$myteam)) { print $message; } else { //daram darbu } Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 30, 2013 Author Report Share Posted April 30, 2013 bet iekšs validatedata jebkurā gadījumā taču tiks atgriezts true/vai kāds strings (kgan šaubos, ka arī false, ko mainītu) un jebkurā gadījumā tiktu "pielipināta" jebkura vērtība pie $message un izpildītos ifs. Vai varbūt es maldos? Quote Link to comment Share on other sites More sharing options...
v3rb0 Posted April 30, 2013 Report Share Posted April 30, 2013 (edited) if($validated != false) Tātad if($validated == true) un nākošajā rindā //error message nerullē neimings. Vai if'ā piešķirt mainīgā vērtību - depends kam un kādā valodas kontekstā prasi, un kāda ir šībrīža Mēness fāze ieteikme uz vēlmi fleimot. Edited April 30, 2013 by v3rb0 Quote Link to comment Share on other sites More sharing options...
rpr Posted April 30, 2013 Report Share Posted April 30, 2013 (edited) nu tā pa lielam jau nav loģiski, ka tu ar vienu metodi mēģini atgriezt gan boolean, gan string. un kā gan var atgriezt veinlaicīgi false + error message? vai arī taisi: if (!$league->validate($team)) { echo $league->error (); } Edited April 30, 2013 by rpr Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 30, 2013 Author Report Share Posted April 30, 2013 khm, nu okē. Montēšu pa parasto tad Quote Link to comment Share on other sites More sharing options...
daGrevis Posted April 30, 2013 Report Share Posted April 30, 2013 Asainments condišenā... Slikti! Quote Link to comment Share on other sites More sharing options...
Kasspars Posted April 30, 2013 Report Share Posted April 30, 2013 ^ Kāpēc? Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 30, 2013 Author Report Share Posted April 30, 2013 (edited) da neko. acis paberzēju :D Edited April 30, 2013 by anonīms Quote Link to comment Share on other sites More sharing options...
codez Posted April 30, 2013 Report Share Posted April 30, 2013 Izmantojam kļūdu apstrādes pareizāko mehānismu - exception: try{ $o->validate($someData); echo "do somthing"; } catch (SomeException $e) { echo $e->getMessage(); } http://codepad.org/2uHG2CHQ Quote Link to comment Share on other sites More sharing options...
daGrevis Posted April 30, 2013 Report Share Posted April 30, 2013 > Kāpēc? Jo tā ļoti viegli var pieļaut stulbas kļūdas. Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 30, 2013 Author Report Share Posted April 30, 2013 oparapapā, paldies codez. Palasīšos Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 30, 2013 Author Report Share Posted April 30, 2013 Baigi dīvaini Mēģinot savienot ar esošo kodu īsti nestrādā class error extends Exception {} ... try{ $leagueClass->validatedata($collected,$myteam,$league['id']); } catch (error $error) { print $error->getMessage(); } Fatal error: Uncaught exception 'error' with message 'Jums savā starpā vairs nav spēles! bet jaunā vidē (pliks php fails) viss ok class error extends Exception {} class league { function validate($bla) { throw new error('bla a ko tu nestradaa?'); } } $league = new league(); try { $league->validate('a'); } catch (error $e){ $e->getMessage(); } Quote Link to comment Share on other sites More sharing options...
rpr Posted April 30, 2013 Report Share Posted April 30, 2013 codez, bet ja nu t'a nav k'l'uda, bet vienk'ar'si pazi'nojums. valid'acija pati par sevi ta'cu nerada k'l'uda, tikai pasaka ir ok vai nav. Quote Link to comment Share on other sites More sharing options...
anonīms Posted April 30, 2013 Author Report Share Posted April 30, 2013 ne vienmēr. Manā gadījumā validācija tiešām arī izmet, kas par kļūdu Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.