marcis Posted June 8, 2011 Report Share Posted June 8, 2011 +1 par Exception. Starpcitu, arī jūsu pieminētie frameworki (Kohana, Fuel) lieto tos pašus Exception'us neveiksmīgas validācijas u.c. gadījumos. Quote Link to comment Share on other sites More sharing options...
briedis Posted June 8, 2011 Report Share Posted June 8, 2011 Tad otrs jautājums, kā šinī sakarā noķert vairākus nederīgus ievadītos laukus? public function register() { $user = new User($_POST['user'], $_POST['mail'], $_POST['birthday'], ...); try { $user->save(); } catch(ValidationException $e) { $this->render('new', array('form_errors' => $e->get_reasons())); } } ..vienkārši tas ir diezgan kaitinoši, kad netiek izvadīti visi kļūdaini lauki uzreiz, bet gan pa vienam :) Quote Link to comment Share on other sites More sharing options...
Rincewind Posted June 8, 2011 Report Share Posted June 8, 2011 Starpcitu, arī jūsu pieminētie frameworki (Kohana, Fuel) lieto tos pašus Exception'us neveiksmīgas validācijas u.c. gadījumos. Yii kodā es neko tādu neredzu, exception pie modeļa validācijas tiek izsaukts tikai ja pats validation rule ir uzrakstīts ar kļūdām. Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted June 8, 2011 Report Share Posted June 8, 2011 (edited) briedis: Kaut kaa taa vareetu // Base Model klasee public function run_validations() { $errors = array(); foreach($this->validations as $validation) { try { $this->validate($validation); } catch(SomeValidationException $e) { $errors[] = $e->get_why_message(); } } if(!empty($errors)) throw new ValidationException($errors); } Eniivei - nezkaadeelj liekas ka te driiz saaksies religjiozie kari :D Edited June 8, 2011 by rATRIJS Quote Link to comment Share on other sites More sharing options...
marcis Posted June 8, 2011 Report Share Posted June 8, 2011 Yii arī nav raķešu zinātne. Visur pieeja viena http://www.yiiframework.com/doc/guide/1.1/en/topics.error#raising-exceptions Tip: Raising a CHttpException exception is a simple way of reporting errors caused by user misoperation. For example, if the user provides an invalid post ID in the URL, we can simply do the following to show a 404 error (page not found) Quote Link to comment Share on other sites More sharing options...
Rincewind Posted June 8, 2011 Report Share Posted June 8, 2011 Yii arī nav raķešu zinātne. Visur pieeja viena http://www.yiiframework.com/doc/guide/1.1/en/topics.error#raising-exceptions Pag, tu tak teici ka freimworks pats izmanto exception pie validācijām, nevis ka viņš ļauj lietotājam viņus izmantot. Vai es kaut ko ne tā sapratu? Quote Link to comment Share on other sites More sharing options...
marcis Posted June 8, 2011 Report Share Posted June 8, 2011 (edited) Tas bija piemērs (par Kohanu), nevis automātiski nozīmē, ka pilnīgi visi frameworki dara tikai tā un ne savādāk. Nav ko cepties. Exception nav nekas slikts un nekur nav teikts, ka šī metode jāizmanto tikai akūtos gadījumos. Edited June 8, 2011 by marcis Quote Link to comment Share on other sites More sharing options...
spainis Posted June 8, 2011 Report Share Posted June 8, 2011 Kohana tak ir validācijas klase, pie tam vēl ar i18n iespējām Quote Link to comment Share on other sites More sharing options...
daGrevis Posted June 8, 2011 Report Share Posted June 8, 2011 Ņemu Savus vārdus atpakaļ. To varētu darīt ar "exception'iem". 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.