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


PHP CommentForm::validate方法代码示例

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


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

示例1: actionCreate

 public function actionCreate($id = 0, $callback)
 {
     // @todo 暂时无用
     if (!request()->getIsAjaxRequest() || !request()->getIsPostRequest()) {
         throw new CHttpException(500);
     }
     $data = array();
     $model = new CommentForm();
     $model->attributes = $_POST['CommentForm'];
     if ($model->validate() && ($comment = $model->save())) {
         $data['errno'] = 0;
         $data['text'] = t('ajax_comment_done');
         $data['html'] = 'x';
         // @todo 反回此条评论的html代码
     } else {
         $data['errno'] = 1;
         $attributes = array_keys($model->getErrors());
         foreach ($attributes as $attribute) {
             $labels[] = $model->getAttributeLabel($attribute);
         }
         $errstr = join(' ', $labels);
         $data['text'] = sprintf(t('ajax_comment_error'), $errstr);
     }
     echo json_encode($data);
     exit(0);
 }
开发者ID:rainsongsky,项目名称:24beta,代码行数:26,代码来源:CommentController.php

示例2: actionComment

 public function actionComment($callback, $id = 0)
 {
     $id = (int) $id;
     $callback = strip_tags(trim($callback));
     if (!request()->getIsAjaxRequest() || !request()->getIsPostRequest() || empty($callback)) {
         throw new CHttpException(500);
     }
     $data = array();
     $model = new CommentForm();
     $model->attributes = $_POST['CommentForm'];
     $model->content = h($model->content);
     if ($id > 0 && ($quote = Comment::model()->findByPk($id))) {
         $quoteTitle = sprintf(t('comment_quote_title'), $quote->authorName);
         $html = '<fieldset class="beta-comment-quote"><legend>' . $quoteTitle . '</legend>' . $quote->content . '</fieldset>';
         $model->content = $html . $model->content;
     }
     if ($model->validate() && ($comment = $model->save())) {
         $data['errno'] = 0;
         $data['text'] = t('ajax_comment_done');
         $data['html'] = $this->renderPartial('/comment/_one', array('comment' => $comment), true);
         // @todo 反回此条评论的html代码
     } else {
         $data['errno'] = 1;
         $attributes = array_keys($model->getErrors());
         foreach ($attributes as $attribute) {
             $labels[] = $model->getAttributeLabel($attribute);
         }
         $errstr = join(' ', $labels);
         $data['text'] = sprintf(t('ajax_comment_error'), $errstr);
     }
     echo $callback . '(' . json_encode($data) . ')';
     exit(0);
 }
开发者ID:rainsongsky,项目名称:24beta,代码行数:33,代码来源:PostController.php

示例3: actionWriteComment

 public function actionWriteComment()
 {
     $model = new CommentForm();
     if (isset($_POST['CommentForm']) && BlockIp::checkAllowIp(Yii::app()->controller->currentUserIpLong)) {
         $model->attributes = $_POST['CommentForm'];
         $model->defineShowRating();
         if ($model->validate() && Comment::checkExist(null, $model->modelName, $model->modelId)) {
             if ($model->modelName == 'News' && !param('enableCommentsForNews', 1) || $model->modelName == 'Apartment' && !param('enableCommentsForApartments', 1) || $model->modelName == 'Menu' && !param('enableCommentsForPages', 0) || $model->modelName == 'Article' && !param('enableCommentsForFaq', 1) || $model->modelName == 'InfoPages' && !param('enableCommentsForPages', 0)) {
                 throw404();
             }
             $comment = new Comment();
             $comment->body = $model->body;
             $comment->parent_id = $model->rel;
             $comment->user_ip = Yii::app()->controller->currentUserIp;
             $comment->user_ip_ip2_long = Yii::app()->controller->currentUserIpLong;
             if ($model->rel == 0) {
                 $comment->rating = $model->rating;
             } else {
                 $comment->rating = -1;
             }
             $comment->model_name = $model->modelName;
             $comment->model_id = $model->modelId;
             if (Yii::app()->user->isGuest) {
                 $comment->user_name = $model->user_name;
                 $comment->user_email = $model->user_email;
             } else {
                 $comment->owner_id = Yii::app()->user->id;
             }
             if (param('commentNeedApproval', 1) && !Yii::app()->user->checkAccess('backend_access')) {
                 $comment->status = Comment::STATUS_PENDING;
                 Yii::app()->user->setFlash('success', Yii::t('module_comments', 'Thank you for your comment. Your comment will be posted once it is approved.'));
             } else {
                 $comment->status = Comment::STATUS_APPROVED;
                 Yii::app()->user->setFlash('success', Yii::t('module_comments', 'Thank you for your comment.'));
             }
             $comment->save(false);
             $this->redirect($model->url);
         }
     }
     $this->render('commentForm', array('model' => $model));
 }
开发者ID:barricade86,项目名称:raui,代码行数:41,代码来源:MainController.php

示例4: addComment

 /**
  * Функция добавление комментов 
  */
 protected function addComment(&$model)
 {
     if (isset($_POST['CommentForm'])) {
         $commentForm = new CommentForm();
         $commentForm->attributes = $_POST['CommentForm'];
         if ($commentForm->validate()) {
             Yii::app()->user->setState('CommentForm', null);
             $comment = new Comment();
             $comment->attributes = $_POST['CommentForm'];
             $comment->object_type = L::r_item('CommentType', get_class($model));
             $comment->object_id = $model->id;
             $comment->created = date('Y-m-d H:i:s');
             $comment->rating = 0;
             $comment->status = L::r_item('commentStatus', 'new');
             if ($parent = Comment::model()->findbyPk((int) $commentForm->parent)) {
                 $parent->append($comment);
             } else {
                 $comment->saveNode();
             }
             Yii::app()->user->setFlash('comment', array('text' => 'Спасибо за Ваш комментарий', 'class' => 'error'));
             $this->redirect(Yii::app()->request->requestUri . '#comment-' . $comment->id);
         } else {
             Yii::app()->user->setState('CommentForm', $commentForm);
         }
     } else {
         Yii::app()->user->setState('CommentForm', null);
     }
 }
开发者ID:BGCX261,项目名称:zoomtyre-svn-to-git,代码行数:31,代码来源:Controller.php

示例5: add

 /**
  * Add a comment
  * @param $args array
  * @param $request Request
  */
 function add($args, $request)
 {
     $articleId = isset($args[0]) ? (int) $args[0] : 0;
     $galleyId = isset($args[1]) ? (int) $args[1] : 0;
     $parentId = isset($args[2]) ? (int) $args[2] : 0;
     $journal =& $request->getJournal();
     $commentDao =& DAORegistry::getDAO('CommentDAO');
     $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
     $publishedArticle =& $publishedArticleDao->getPublishedArticleByArticleId($articleId);
     $parent =& $commentDao->getById($parentId, $articleId);
     if (isset($parent) && $parent->getSubmissionId() != $articleId) {
         $request->redirect(null, null, 'view', array($articleId, $galleyId));
     }
     $this->validate($request, $articleId);
     $this->setupTemplate($request, $publishedArticle, $galleyId, $parent);
     // Bring in comment constants
     $enableComments = $journal->getSetting('enableComments');
     switch ($enableComments) {
         case COMMENTS_UNAUTHENTICATED:
             break;
         case COMMENTS_AUTHENTICATED:
         case COMMENTS_ANONYMOUS:
             // The user must be logged in to post comments.
             if (!$request->getUser()) {
                 Validation::redirectLogin();
             }
             break;
         default:
             // Comments are disabled.
             Validation::redirectLogin();
     }
     import('classes.comment.form.CommentForm');
     $commentForm = new CommentForm(null, $articleId, $galleyId, isset($parent) ? $parentId : null);
     $commentForm->initData();
     if (isset($args[3]) && $args[3] == 'save') {
         $commentForm->readInputData();
         if ($commentForm->validate()) {
             $commentForm->execute();
             // Send a notification to associated users
             import('classes.notification.NotificationManager');
             $notificationManager = new NotificationManager();
             $articleDao =& DAORegistry::getDAO('ArticleDAO');
             $article =& $articleDao->getArticle($articleId);
             $notificationUsers = $article->getAssociatedUserIds();
             foreach ($notificationUsers as $userRole) {
                 $notificationManager->createNotification($request, $userRole['id'], NOTIFICATION_TYPE_USER_COMMENT, $article->getJournalId(), ASSOC_TYPE_ARTICLE, $article->getId());
             }
             $request->redirect(null, null, 'view', array($articleId, $galleyId, $parentId), array('refresh' => 1));
         }
     }
     $commentForm->display();
 }
开发者ID:yuricampos,项目名称:ojs,代码行数:57,代码来源:CommentHandler.inc.php

示例6: add

 function add($args)
 {
     $paperId = isset($args[0]) ? (int) $args[0] : 0;
     $galleyId = isset($args[1]) ? (int) $args[1] : 0;
     $parentId = isset($args[2]) ? (int) $args[2] : 0;
     $conference =& Request::getConference();
     $schedConf =& Request::getSchedConf();
     $this->validate($paperId);
     $paper =& $this->paper;
     $parent =& $commentDao->getComment($parentId, $paperId);
     if (isset($parent) && $parent->getPaperId() != $paperId) {
         Request::redirect(null, null, null, 'view', array($paperId, $galleyId));
     }
     $this->setupTemplate($paper, $galleyId, $parent);
     // Bring in comment constants
     $commentDao =& DAORegistry::getDAO('CommentDAO');
     $enableComments = $conference->getSetting('enableComments');
     $commentsRequireRegistration = $conference->getSetting('commentsRequireRegistration');
     $commentsAllowAnonymous = $conference->getSetting('commentsAllowAnonymous');
     $closeCommentsDate = $schedConf->getSetting('closeCommentsDate');
     $commentsClosed = $schedConf->getSetting('closeComments') ? true : false && strtotime($closeCommentsDate < time());
     $enableComments = $enableComments && !$commentsClosed && $paper->getEnableComments();
     if (!$enableComments) {
         Request::redirect(null, null, 'index');
     }
     if ($commentsRequireRegistration && !Request::getUser()) {
         Validation::redirectLogin();
     }
     import('comment.form.CommentForm');
     $commentForm = new CommentForm(null, $paperId, $galleyId, isset($parent) ? $parentId : null);
     $commentForm->initData();
     if (isset($args[3]) && $args[3] == 'save') {
         $commentForm->readInputData();
         if ($commentForm->validate()) {
             $commentForm->execute();
             // Send a notification to associated users
             import('notification.Notification');
             $paperDAO =& DAORegistry::getDAO('PaperDAO');
             $paper =& $paperDAO->getPaper($paperId);
             $notificationUsers = $paper->getAssociatedUserIds();
             foreach ($notificationUsers as $userRole) {
                 $url = Request::url(null, null, null, 'view', array($paperId, $galleyId, $parentId));
                 Notification::createNotification($userRole['id'], "notification.type.userComment", $paper->getLocalizedTitle(), $url, 1, NOTIFICATION_TYPE_USER_COMMENT);
             }
             Request::redirect(null, null, null, 'view', array($paperId, $galleyId, $parentId), array('refresh' => 1));
         }
     }
     $commentForm->display();
 }
开发者ID:jalperin,项目名称:ocs,代码行数:49,代码来源:CommentHandler.inc.php


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