本文整理汇总了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)));
}
示例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,
));*/
}