当前位置: 首页>>代码示例>>PHP>>正文


PHP Option::validate方法代码示例

本文整理汇总了PHP中Option::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Option::validate方法的具体用法?PHP Option::validate怎么用?PHP Option::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Option的用法示例。


在下文中一共展示了Option::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store($quiz_id)
 {
     try {
         DB::beginTransaction();
         $quiz = Quiz::find($quiz_id);
         foreach (Input::get('question') as $input_question) {
             $question_params = array("name" => $input_question['name']);
             $question_validator = Question::validate($question_params);
             if ($question_validator->fails()) {
                 throw new Exception("Question can't be saved");
             }
             $question = new Question($question_params);
             $question = $quiz->questions()->save($question);
             foreach ($input_question['options'] as $value) {
                 $option_params = array("name" => $value['name'], "is_correct" => array_key_exists("is_correct", $value) ? true : false);
                 $option_validator = Option::validate($option_params);
                 if ($option_validator->fails()) {
                     throw new Exception("Option can't be saved");
                 }
                 $option = new Option($option_params);
                 $option = $question->options()->save($option);
             }
         }
         DB::commit();
         return Redirect::to("quizzes/" . $quiz->id . '/questions');
     } catch (Exception $e) {
         DB::rollback();
         //throw new Exception($e);
         return Redirect::to('quizzes/' . $quiz->id . '/questions/create');
     }
 }
开发者ID:shankargiri,项目名称:Quantum-Vic-La-Trobe-L4,代码行数:36,代码来源:QuestionsController.php

示例2: actionCreate

 public function actionCreate()
 {
     $model = new Option();
     $description = new OptionDescription();
     $optionValue = new OptionValue();
     $optionValueDes = new OptionValueDescription();
     //$optionValueData = new CArrayDataProvider($this->_optionvalue);
     $this->performAjaxValidation(array($model, $description, $optionValue), 'option-form');
     if (isset($_POST[$this->modelName])) {
         $model->setAttributes($_POST[$this->modelName]);
         $description->setAttributes($_POST[$this->modelName . 'Description']);
         //$optionValue->setAttributes($_POST['OptionValue']);
         $suc = Yii::t('info', 'Option was successfully created');
         $err = Yii::t('info', 'Could not update Option');
         $errOpt = Yii::t('info', 'Please fill in the name and sort number for each option value');
         $description->option_id = 0;
         $description->locale_code = Yii::app()->getLanguage();
         if ($model->validate() && $description->validate() && $this->validateOptionValue()) {
             if ($model->save()) {
                 $description->option_id = $model->id;
                 $description->save();
                 foreach ($this->_optionvalue as $i => $optionvalue) {
                     $optionvalue->option_id = $model->id;
                     $optionvalue->save();
                     $this->_optionvaluedes[$i]->option_value_id = $optionvalue->id;
                     $this->_optionvaluedes[$i]->option_id = $model->id;
                     $this->_optionvaluedes[$i]->save();
                 }
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc);
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_view', array('model' => $model, 'description' => $description, 'optionValue' => $this->_optionvalue, 'optionValueDes' => $this->_optionvaluedes, 'optionValueData' => new CArrayDataProvider($this->_optionvalue)), false, true);
                     Yii::app()->end();
                 } else {
                     $this->redirect(array('view', 'id' => $model->id));
                 }
             } else {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err);
             }
         } else {
             $description->validate();
             if (!$this->validateOptionValue()) {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $errOpt);
             }
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form', array('model' => $model, 'description' => $description, 'optionValue' => $this->_optionvalue, 'optionValueDes' => $this->_optionvaluedes, 'optionValueData' => new CArrayDataProvider($this->_optionvalue)), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'description' => $description, 'optionValue' => $this->_optionvalue, 'optionValueDes' => $this->_optionvaluedes, 'optionValueData' => new CArrayDataProvider($this->_optionvalue)));
 }
开发者ID:Rudianasaja,项目名称:cycommerce,代码行数:51,代码来源:OptionController.php


注:本文中的Option::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。