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


PHP Answer::validate方法代码示例

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


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

示例1: actionView

 /** 
  * Controller action for viewing a questions.
  * Also provides functionality for creating an answer,
  * adding a comment and voting.
  */
 public function actionView()
 {
     error_reporting(E_ALL);
     ini_set("display_errors", 1);
     $question = Question::model()->findByPk(Yii::app()->request->getParam('id'));
     if (isset($_POST['Answer'])) {
         $answerModel = new Answer();
         $answerModel->attributes = $_POST['Answer'];
         $answerModel->created_by = Yii::app()->user->id;
         $answerModel->post_type = "answer";
         $answerModel->question_id = $question->id;
         if ($answerModel->validate()) {
             $answerModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id)));
         }
     }
     if (isset($_POST['Comment'])) {
         $commentModel = new Comment();
         $commentModel->attributes = $_POST['Comment'];
         $commentModel->created_by = Yii::app()->user->id;
         $commentModel->post_type = "comment";
         $commentModel->question_id = $question->id;
         if ($commentModel->validate()) {
             $commentModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id)));
         }
     }
     // User has just voted on a question
     if (isset($_POST['QuestionVotes'])) {
         $questionVotesModel = new QuestionVotes();
         $questionVotesModel->attributes = $_POST['QuestionVotes'];
         QuestionVotes::model()->castVote($questionVotesModel, $question->id);
     }
     $this->render('view', array('author' => $question->user->id, 'question' => $question, 'answers' => Answer::model()->overview($question->id), 'related' => Question::model()->related($question->id)));
 }
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:40,代码来源:MainController.php

示例2: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $answer = new Answer();
     if (isset($_POST['Answer'])) {
         $this->forcePostRequest();
         $_POST = Yii::app()->input->stripClean($_POST);
         $answer->attributes = $_POST['Answer'];
         $answer->content->populateByForm();
         $answer->post_type = "answer";
         if ($answer->validate()) {
             $answer->save();
             $this->redirect(array('//questionanswer/question/view', 'id' => $answer->question_id));
         }
     }
     /*$model=new Answer;
     
     		// Uncomment the following line if AJAX validation is needed
     		// $this->performAjaxValidation($model);
     
     		if(isset($_POST['Answer']))
     		{
     			$model->attributes=$_POST['Answer'];
     	        $model->created_by = Yii::app()->user->id;
     	        $model->post_type = "answer";
     
     			if($model->save())
     				$this->redirect(array('//questionanswer/question/view','id'=>$model->question_id));
     		}
     
     		$this->render('create',array(
     			'model'=>$model,
     		));*/
 }
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:37,代码来源:AnswerController.php


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