本文整理汇总了PHP中CommentForm::save方法的典型用法代码示例。如果您正苦于以下问题:PHP CommentForm::save方法的具体用法?PHP CommentForm::save怎么用?PHP CommentForm::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommentForm
的用法示例。
在下文中一共展示了CommentForm::save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例3: executeFormWidget
public function executeFormWidget(dmWebRequest $request)
{
$form = new CommentForm();
if ($request->isMethod('post')) {
$captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'));
$form->bind(array_merge($request->getParameter($form->getName()), array('captcha' => $captcha)));
if ($form->isValid()) {
$form->save();
$this->getUser()->setFlash('form_saved', true);
$this->redirectBack();
}
}
$this->forms['Comment'] = $form;
}
示例4: executeComment
public function executeComment(sfWebRequest $request)
{
$comment = new Comment();
$comment->setTicketId($request->getParameter('id'));
$form = new CommentForm($comment);
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
$this->getUser()->setFlash('message', array('success', 'Отлично!', 'Комментарий добавлен.'));
$comment = $form->save();
$this->redirect('@tickets-show?id=' . $comment->getTicketId());
} else {
//$this->redirect('@tickets-show?id=' . $request->getParameter('id'));
$this->form = $form;
}
}