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


PHP Question::save方法代码示例

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


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

示例1: executeInjection

 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeInjection(sfWebRequest $request)
  {
	$this->form = new InjectionForm();
    if ($request->isMethod('post'))
    {
		$this->form->bind($request->getParameter('injection'), $request->getFiles('injection'));
		if ($this->form->isValid())
		{
		  $file = $this->form->getValue('fichier');
		  $file->save(sfConfig::get('sf_upload_dir').'/injection.csv');
		  
			if (($handle = fopen(sfConfig::get('sf_upload_dir').'/injection.csv', "r")) !== FALSE) {
				while (($data = fgetcsv($handle, 0, ";")) !== FALSE) {
					if ($data[9] != '') {
						$question = new Question();
						$question->setNom($data[4]);
						$question->setPrenom($data[5]);
						$question->setCodePostal($data[6]);
						$question->setPays($data[7]);
						$question->setTelephone($data[9]);
						$question->setEmail($data[8]);
						$question->setTexteQuestion(str_replace("\\", "", $data[3]));
	//					$question->setSite("lejuridique");
						$question->setDateQuestion($data[2]);
						$question->save();
					}
				}
				fclose($handle);
			}		  
		}
    }
	
  }
开发者ID:nacef,项目名称:juriste,代码行数:38,代码来源:actions.class.php

示例2: postAdminCreateQuestions

 public function postAdminCreateQuestions()
 {
     $validate = Validator::make(Input::all(), array('question' => 'required', 'type' => 'required'));
     if ($validate->fails()) {
         return Redirect::route('getAdminEditQuestions', $question->id)->withErrors($validate)->withInput();
     } else {
         $question = new Question();
         $question->text = Input::get('question');
         $question->type = Input::get('type');
         try {
             $question->save();
             $formAnswers = Input::get('answers');
             $answers = array();
             $countOfAnswers = 0;
             if (Input::get('type') == 0) {
                 $countOfAnswers = 3;
             } else {
                 $countOfAnswers = 4;
             }
             for ($i = 0; $i < $countOfAnswers; $i++) {
                 $answers[] = new Answer(array('text' => $formAnswers[$i]));
             }
             $question->answers()->saveMany($answers);
             return Redirect::route('getAdminEditQuestions', $question->id);
         } catch (Exception $ex) {
             return Redirect::route('getAdminEditQuestions', $question->id);
         }
     }
 }
开发者ID:EmilAleksandrov,项目名称:cinegrand-game,代码行数:29,代码来源:AdminController.php

示例3: actionCreate

 public function actionCreate()
 {
     $result = new stdClass();
     $post = $this->getRequestBody();
     if ($post === null) {
         $result->status = "request is empty";
     } elseif (empty($post->content)) {
         $result->status = "'content' parameter is empty";
     } elseif (empty($post->poll_id)) {
         $result->status = "'poll_id' parameter is empty";
     } elseif (!isset($post->weight)) {
         $result->status = "'weight' parameter is not set";
     } elseif (!isset($post->mandatory)) {
         $result->status = "'mandatory' parameter is not set";
     } elseif (!isset($post->multiple)) {
         $result->status = "'multiple' parameter is not set";
     } else {
         $poll = Poll::findById($post->poll_id);
         if (empty($poll)) {
             $result->status = '404 Not found';
         } else {
             $question = new Question();
             $question->content = trim($post->content);
             $question->weight = $post->weight;
             $question->mandatory = $post->mandatory;
             $question->multiple = $post->multiple;
             $question->poll = $poll;
             $question->save();
             $result->status = 'ok';
             $result->data = $question->formStdObject();
         }
     }
     echo json_encode($result);
     exit;
 }
开发者ID:dyurusov,项目名称:poll-example,代码行数:35,代码来源:QuestionController.php

示例4: store

 /**
  * Store a newly created post in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validate = Validator::make(Input::all(), Question::$rules);
     if ($validate->passes()) {
         //save a new Question
         $question = new Question();
         $question->title = Input::get('title');
         $question->body = Input::get('body');
         $question->user_id = Auth::id();
         $question->save();
         $question_id = $question->id;
         //saving Tags in Tag Table
         /*	convert input to array 	*/
         $tags_arr = explode(',', Input::get('tag'));
         /*	
         save in Tag table and return object for saving in 
         Tagmap table
         */
         foreach ($tags_arr as $tag_str) {
             $tag_obj = Tag::firstOrCreate(array('title' => $tag_str));
             //this line will attach a tag ( insert and save automatically )
             $new_question->tags()->attach($tag_obj->id);
         }
         return Redirect::action('QuestionController@index');
     }
     return Redirect::back()->withErrors($validate)->withInput();
 }
开发者ID:ayooby,项目名称:whatisit,代码行数:32,代码来源:QuestionController.php

示例5: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $question = new Question();
     if (isset($_POST['Question'])) {
         $this->forcePostRequest();
         $_POST = Yii::app()->input->stripClean($_POST);
         $question->attributes = $_POST['Question'];
         $question->content->populateByForm();
         $question->post_type = "question";
         if ($question->validate()) {
             $question->save();
             if (isset($_POST['Tags'])) {
                 // Split tag string into array
                 $tags = explode(", ", $_POST['Tags']);
                 foreach ($tags as $tag) {
                     $tag = Tag::model()->firstOrCreate($tag);
                     $question_tag = new QuestionTag();
                     $question_tag->question_id = $question->id;
                     $question_tag->tag_id = $tag->id;
                     $question_tag->save();
                 }
             }
             $this->redirect($this->createUrl('//questionanswer/question/view', array('id' => $question->id)));
         }
     }
     $this->render('create', array('model' => $question));
 }
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:31,代码来源:QuestionController.php

示例6: makeQuestion

 public function makeQuestion()
 {
     $data = Input::all();
     $rules = ['question' => 'required', 'opt1' => 'required', 'opt2' => 'required', 'opt3' => 'required'];
     $validator = Validator::make($data, $rules);
     if ($validator->passes()) {
         $question = new Question();
         $question->question = $data['question'];
         if ($question->save()) {
             try {
                 for ($i = 1; $i < 4; $i++) {
                     $option = new QuestionOption();
                     $option->question_id = $question->id;
                     $option->option_details = $data["opt{$i}"];
                     $option->option_number = $i;
                     $option->save();
                 }
             } catch (Exception $e) {
                 Redirect::back()->withInfo('Something Interuppted');
             }
         } else {
             Redirect::back()->withInfo('Something Interuppted');
         }
         return Redirect::to('adm/h');
     } else {
         return Redirect::back()->withErrors($validator->messages());
     }
 }
开发者ID:nayeemjoy,项目名称:maskcamp,代码行数:28,代码来源:AdminController.php

示例7: makeNewQues

 public function makeNewQues($batchid)
 {
     $question = new Question();
     $question->user_id = Auth::id();
     $question->batchentry_id = $batchid;
     $question->complete = 0;
     $question->save();
     Session::put('currentqid', $question->id);
     return $question->id;
 }
开发者ID:nverdhan,项目名称:qdbwrite,代码行数:10,代码来源:Question.php

示例8: admin_add_question

 public function admin_add_question()
 {
     $question = null;
     if (array_key_exists('question', $_POST)) {
         $question = new Question($this->question_collection, $_POST['question']);
         $question->save();
         header("Location: /?p=admin");
     }
     $this->load_template('admin/add_question');
     return $this->render($question);
 }
开发者ID:xwiz,项目名称:personality-quiz,代码行数:11,代码来源:app.php

示例9: store

 /**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['title' => 'required|max:150', 'description' => 'required']);
     if ($validator->fails()) {
         return response()->json($validator->errors(), 400);
     } else {
         $question = new Question(['title' => $request->title, 'description' => $request->description, 'user_id' => Auth::user()->id]);
         $question->save();
         return response()->json($question, 201);
     }
 }
开发者ID:AlMos321,项目名称:laravel,代码行数:17,代码来源:SerialController.php

示例10: newquestion

 function newquestion($data)
 {
     if ($data['title'] && $data['explanation']) {
         $newquestion = new Question();
         $newquestion->title = $data['title'];
         $newquestion->explanation = sqlite_escape_string($data['explanation']);
         $newquestion->save();
         return true;
     } else {
         return false;
     }
 }
开发者ID:stas,项目名称:bebuntu,代码行数:12,代码来源:questions-controller.php

示例11: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Question();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Question'])) {
         $model->attributes = $_POST['Question'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:CODEPAC,项目名称:codepac,代码行数:17,代码来源:QuestionController.php

示例12: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($quizId, $type = "multiple-choice")
 {
     Yii::import('ext.multimodelform.MultiModelForm');
     $model = new Question();
     //the Group model
     $model->quizId = $quizId;
     $model->type = $type;
     $quiz = $this->loadQuiz($quizId);
     $choice = new Answer();
     $validatedChoices = array();
     //ensure an empty array
     if (isset($_POST['Question'])) {
         $model->attributes = $_POST['Question'];
         $model->save();
         //the value for the foreign key 'groupid'
         $masterValues = array('questionId' => $model->id);
         if (MultiModelForm::save($choice, $validatedChoices, $deleteMembers, $masterValues) && $model->save()) {
             $this->redirect(array('quiz/view', 'id' => $quiz->id));
         }
     }
     $this->render('create', array('model' => $model, 'choice' => $choice, 'validatedChoices' => $validatedChoices, 'lesson' => $quiz->lesson, 'quiz' => $quiz, 'course' => $quiz->lesson->course));
 }
开发者ID:stan5621,项目名称:jp_edu_online,代码行数:26,代码来源:QuestionController.php

示例13: store

 /**
  * Store a newly created resource in storage.
  * POST /commonquestions
  *
  * @return Response
  */
 public function store()
 {
     $validator = Question::validate(Input::only('topic', 'description'));
     if ($validator->fails()) {
         return Redirect::to('/commonCreate')->withErrors($validator)->withInput(Input::all());
     } else {
         $question = new Question();
         $question->topic = Input::get('topic');
         $question->description = Input::get('description');
         if ($question->save()) {
             return Redirect::to('/common');
         }
     }
 }
开发者ID:shankargiri,项目名称:taylor_latest,代码行数:20,代码来源:CommonquestionsController.php

示例14: storeAction

 /**
  * Storing new question
  *
  * @return mixed
  */
 public function storeAction()
 {
     $data = Input::all();
     $num = (int) $data['number_of_answers'];
     $test = Test::find($data['test_id']);
     if (is_null($test)) {
         return Redirect::route('tests.index')->with('error', 'Incorrect test id');
     }
     /**
      * Check if we have results already
      */
     if (count(Result::where('test_id', $test->id)->get())) {
         return Redirect::route('tests.index')->with('error', 'Нельзя редактировать тест, на который есть ответы');
     }
     $validation = Validator::make(['text' => $data['text']], Question::$rules);
     if (!$validation->passes()) {
         return Redirect::route('question.create', ['id' => $test->id])->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
     }
     $question = new Question();
     $question->text = $data['text'];
     $question->number = (int) $data['number'];
     $question->type = $data['type'] ? $data['type'] : Question::TYPE_STRING;
     $question->test_id = $test->id;
     $question->save();
     /**
      * Create answers
      */
     for ($i = 1; $i <= $num; $i++) {
         if (!isset($data['a_' . $i . '_text']) || !trim($data['a_' . $i . '_text'])) {
             continue;
         }
         $answer = new Answer();
         $answer->question_id = $question->id;
         $answer->text = trim($data['a_' . $i . '_text']);
         $answer->weight = (int) $data['a_' . $i . '_weight'];
         if ($question->type == Question::TYPE_CHECKBOX) {
             $answer->is_correct = isset($data['a_' . $i . '_correct']) ? true : false;
         } elseif ($question->type == Question::TYPE_RADIO) {
             $answer->is_correct = isset($data['a_0_correct']) && $data['a_0_correct'] == $i ? true : false;
         }
         if ($answer->is_correct && !$answer->weight) {
             $answer->weight = 1;
         }
         if (!$answer->is_correct) {
             $answer->weight = 0;
         }
         $answer->save();
     }
     return Redirect::route('tests.show', $test->id);
 }
开发者ID:himor,项目名称:testing,代码行数:55,代码来源:QuestionController.php

示例15: executeAdd

 public function executeAdd()
 {
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         // create question
         $user = $this->getUser()->getSubscriber();
         $question = new Question();
         $question->setTitle($this->getRequestParameter('title'));
         $question->setBody($this->getRequestParameter('body'));
         $question->setUser($user);
         $question->save();
         $user->isInterestedIn($question);
         $question->addTagsForUser($this->getRequestParameter('tag'), $user->getId());
         return $this->redirect('@question?stripped_title=' . $question->getStrippedTitle());
     }
 }
开发者ID:emacsattic,项目名称:symfony,代码行数:15,代码来源:actions.class.php


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