本文整理汇总了PHP中common\models\Comment类的典型用法代码示例。如果您正苦于以下问题:PHP Comment类的具体用法?PHP Comment怎么用?PHP Comment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Comment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: actionAddComment
public function actionAddComment()
{
if (\Yii::$app->request->isAjax) {
$model = new Comment();
if (\Yii::$app->user->isGuest) {
$model->scenario = 'isGuest';
}
$data = ['error' => true];
if ($model->load(\Yii::$app->request->post())) {
$parentID = \Yii::$app->request->post('parent_id');
$root = $model->makeRootIfNotExist();
if (!$parentID) {
$model->appendTo($root);
} else {
$parent = Comment::find()->where(['id' => $parentID])->one();
$model->appendTo($parent);
}
$articleModel = Article::findOne($model->model_id);
$data = ['replaces' => [['what' => '#comments', 'data' => $this->renderAjax('@app/themes/basic/modules/article/views/default/_comments', ['model' => $articleModel])]]];
}
return Json::encode($data);
} else {
throw new NotFoundHttpException(\Yii::t('app', 'Page not found'));
}
}
开发者ID:tolik505,项目名称:bl,代码行数:25,代码来源:DefaultController.php
示例2: findComments
/**
*
* @param int $data
* @return \yii\data\ActiveDataProvider
*/
public static function findComments($data = array())
{
if (!isset($data['limit'])) {
$data['limit'] = 10;
}
$model = new Comment();
$dataProvider = new ActiveDataProvider(['query' => $model->find()->Where('is_public=:isp and top_id=0 and c_type="article" ', [':isp' => $data['is_public']])->orderBy(" id desc ")->limit($data['limit']), 'pagination' => ['pagesize' => $data['limit']]]);
return $dataProvider;
}
开发者ID:wxzuan,项目名称:wxzuan,代码行数:14,代码来源:CommentService.php
示例3: actionComment
public function actionComment($id)
{
$model = new Comment();
$model->load(Yii::$app->request->post());
$model->article_id = $id;
if ($model->validate()) {
$model->save();
Yii::$app->session->setFlash("success", "Ок");
}
$this->redirect(["article/view", "id" => $id]);
}
开发者ID:horechek,项目名称:nnews,代码行数:11,代码来源:ArticleController.php
示例4: actionView
public function actionView($slug)
{
$commentForm = new Comment();
if ($commentForm->load(Yii::$app->request->post())) {
if ($commentForm->save()) {
Yii::$app->session->setFlash('success', '评论发表成功');
} else {
Yii::$app->session->setFlash('error', '评论发表失败');
}
}
return $this->render('view', ['article' => Page::getInstance()->getBySlug($slug), 'commentForm' => $commentForm]);
}
开发者ID:luobenyu,项目名称:blog-1,代码行数:12,代码来源:PageController.php
示例5: actionIndex
/**
* Displays homepage.
*
* @return mixed
*/
public function actionIndex()
{
$model = new Comment();
if ($model->load(Yii::$app->request->post())) {
$model->is_active = 0;
$model->created_at = date('Y-m-d H:i:s');
$model->updated_at = date('Y-m-d H:i:s');
$model->save();
Yii::$app->session->setFlash('success', 'Thank you! Your comment has been added successfully. It will be available after moderation ;)');
return $this->redirect('/');
}
return $this->render('comments', ['model' => $model]);
}
开发者ID:roman-gich,项目名称:comments,代码行数:18,代码来源:SiteController.php
示例6: actionAddComment
public function actionAddComment()
{
$productId = Yii::$app->request->post('productId');
$rank = Yii::$app->request->post('rank');
$content = Yii::$app->request->post('content');
$comment = new Comment();
$comment->attributes = ['product_id' => $productId, 'user_id' => Yii::$app->user->identity->id, 'rank' => $rank, 'content' => $content];
if ($comment->save(true)) {
return ['status' => true, 'message' => '成功'];
} else {
return ['status' => false, 'message' => '失败: ' . Html::errorSummary($comment)];
}
}
开发者ID:su-xiaolin,项目名称:ICShop-Yii,代码行数:13,代码来源:ProductController.php
示例7: save
/**
* 保存商品
*/
public function save()
{
$newComent = new Comment();
$newComent->setAttributes($this->attributes);
$newComent->setAttribute('c_type', 'article');
$newComent->setAttribute("c_addtime", date('Y-m-d H:i:s'));
if ($newComent->save()) {
$logisct_id = \Yii::$app->db->lastInsertID;
return $logisct_id;
} else {
return FALSE;
}
}
开发者ID:wxzuan,项目名称:wxzuan,代码行数:16,代码来源:SayingForm.php
示例8: actionView
/**
* Displays a single Post model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$list_comment = new ActiveDataProvider(['query' => Comment::find()->where(['post_id' => $id, 'status' => 1])]);
$model_comment = new Comment();
if ($model_comment->load(Yii::$app->request->post())) {
$model_comment->post_id = $id;
$model_comment->status = 0;
if ($model_comment->save()) {
Yii::$app->session->setFlash('success', 'Ваш комментарий был отправлен администраторам сайта и будет опубликован после проверки..');
} else {
Yii::$app->session->setFlash('error', 'Ваш комментарий не был отправлен по техническим причинам. Попробуйте ещё раз.');
}
}
return $this->render('view', ['model' => $this->findModel($id), 'list_comment' => $list_comment, 'model_comment' => $model_comment]);
}
开发者ID:kuzma17,项目名称:paveldent,代码行数:20,代码来源:PostController.php
示例9: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Comment::find();
$commentTable = Comment::tableName();
$user = Yii::$app->getModule("user")->model("User");
// set up query with relation to `user.username`
$userTable = $user::tableName();
$query->joinWith(['user' => function ($query) use($userTable) {
$query->from(['user' => $userTable]);
}]);
$profileTable = \common\modules\user\models\Profile::tableName();
$query->joinWith(['profile' => function ($query) use($profileTable) {
$query->from(['profile' => $profileTable]);
}]);
$dataProvider = new ActiveDataProvider(['query' => $query]);
// enable sorting for the related columns
$addSortAttributes = ["user.username", 'profile.full_name'];
foreach ($addSortAttributes as $addSortAttribute) {
$dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
}
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$createdTime = strtotime($this->created_at);
$startDay = date("Y-m-d 00:00:00", $createdTime);
$endDay = date("Y-m-d 00:00:00", $createdTime + 60 * 60 * 24);
if ($this->created_at) {
$query->andFilterWhere(['between', 'created_at', $startDay, $endDay]);
}
$query->andFilterWhere(["{$commentTable}.id" => $this->id, "{$commentTable}.user_id" => $this->user_id, 'parent_id' => $this->parent_id]);
$query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')])->andFilterWhere(['like', 'profile.full_name', $this->getAttribute('profile.full_name')]);
return $dataProvider;
}
开发者ID:alexsynytskiy,项目名称:Dynamomania,代码行数:40,代码来源:CommentSearch.php
示例10: run
public function run()
{
$commentModel = new Comment();
if (\Yii::$app->user->isGuest) {
$commentModel->scenario = 'isGuest';
}
$commentModel->model_name = $this->model->formName();
$commentModel->model_id = $this->model->id;
$root = $commentModel->getRoot();
if ($root) {
$commentModels = $root->getChildren();
} else {
$commentModels = [];
}
return $this->render('default', ['commentModel' => $commentModel, 'model' => $this->model, 'commentModels' => $commentModels]);
}
开发者ID:tolik505,项目名称:bl,代码行数:16,代码来源:Widget.php
示例11: actionArticle
/**
* 显示一个文章的信息
* @return type
*/
public function actionArticle()
{
$id = \Yii::$app->request->get('id');
$idTrue = true;
if (empty($id)) {
$idTrue = FALSE;
}
if ($idTrue) {
$articleInfo = Comment::find()->where('id=:id', [':id' => $id])->one();
if (!$articleInfo) {
$idTrue = FALSE;
} else {
if ($articleInfo->is_public === 0 && \Yii::$app->user->getId() !== $articleInfo->to_user_id && \Yii::$app->user->getId() !== $articleInfo->user_id) {
$idTrue = FALSE;
}
}
}
if (!$idTrue) {
$error = '当前评论不存在或者已经被禁止显示';
$notices = array('type' => 2, 'msgtitle' => '错误的访问', 'message' => $error, 'backurl' => Url::toRoute('/say/index'), 'backtitle' => '返回');
Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
$this->redirect(Url::toRoute('/public/notices'));
}
return $this->render('article', ['articleInfo' => $articleInfo]);
}
开发者ID:wxzuan,项目名称:wxzuan,代码行数:29,代码来源:SayController.php
示例12: actionIndex
public function actionIndex()
{
$page = $this->helpGquery('page', 1);
$size = 9;
$offset = ($page - 1) * $size;
$comment = new Comment();
$values = $comment->getComments(null, $offset, $size, null);
$comments = $values['list'];
array_walk($comments, function (&$value, $key) {
$value['addtime'] = date('Y-m-d H:i', $value['addtime']);
});
$total = $values['total'];
$pageHTML = $this->getPageHTML($page, $size, $total);
$params = ['comments' => $comments, 'pageHTML' => $pageHTML];
return $this->render('index', $params);
}
开发者ID:VampireMe,项目名称:admin-9939-com,代码行数:16,代码来源:CommentController.php
示例13: getComment
/**
* Возвращает комментарий.
* @param int $id идентификатор комментария
* @throws NotFoundHttpException
* @return Comment
*/
public function getComment($id)
{
if (($model = Comment::findOne($id)) !== null && $model->isPublished()) {
return $model;
} else {
throw new NotFoundHttpException('The requested post does not exist.');
}
}
开发者ID:richardcj,项目名称:Blog-Yii2,代码行数:14,代码来源:Comment.php
示例14: actionIndex
public function actionIndex($id)
{
$user = User::findIdentity($id);
$comments = Comment::getRecentComments();
$sidebarCategories = Category::getSidebarCategories();
$tags = Tag::getTagList();
return $this->render('index', ['user' => $user, 'comments' => $comments, 'sidebarCategories' => $sidebarCategories, 'tags' => $tags]);
}
开发者ID:BorisMatonickin,项目名称:yiicms,代码行数:8,代码来源:ProfileController.php
示例15: actionView
public function actionView($slug)
{
$post = Post::findOne(['slug' => $slug]);
$comment = new Comment();
$comment->name = '';
$comment->email = '';
$comment->body = '';
if ($comment->load(Yii::$app->request->post())) {
$comment->status = 0;
if ($comment->save()) {
Yii::$app->session->setFlash('success', ['type' => 'success', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'You\'re comment successfully stored and will shown after approval.', 'title' => 'Saving Comment']);
} else {
Yii::$app->session->setFlash('error', ['type' => 'danger', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'Sorry but we couldn\'t store your comment.', 'title' => 'Saving Comment']);
}
}
return $this->render('view', ['post' => $post, 'comment' => $comment]);
}
开发者ID:ninjacto,项目名称:ninjacto.com,代码行数:17,代码来源:BlogController.php
示例16: findModel
/**
* Finds the Comment model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Comment the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Comment::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
开发者ID:viktornord,项目名称:gh-php-blog,代码行数:15,代码来源:CommentController.php
示例17: actionAddComment
/**
* @return array
* Добавление комментария
*/
public function actionAddComment()
{
if (\Yii::$app->request->isAjax) {
\Yii::$app->response->format = Response::FORMAT_JSON;
$model = new Comment();
$model->user_id = \Yii::$app->user->identity->id;
$model->event_id = $_POST['event_id'];
$model->message = $_POST['message'];
$model->created = time();
if ($model->save()) {
if (isset($_POST['notify_all']) && $_POST['notify_all'] == 'true') {
EventForm::commenatAllNotification($_POST['event_id'], $_POST['message']);
}
return ['item' => $model, 'user' => $model->user];
}
}
}
开发者ID:KPEMATOP,项目名称:findspree_old,代码行数:21,代码来源:CommentController.php
示例18: save
public function save()
{
$comment = Comment::findOne($this->commentID);
$comment->setAttributes(['author' => $this->author, 'text' => $this->text, 'email' => $this->email, 'published' => $this->published, 'deleted' => $this->deleted]);
if ($comment->save(false)) {
\Yii::$app->session->setFlash('saved', 'Комментарий сохранён!');
} else {
\Yii::$app->session->setFlash('error', 'Комментарий не сохранён!');
}
}
开发者ID:BoBRoID,项目名称:new.k-z,代码行数:10,代码来源:CommentForm.php
示例19: actionView
/**
* Displays a single Suggestion model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$comment = new Comment();
if (Yii::$app->request->post()) {
$comment->sugg_id = $id;
$comment->part_id = strval(Yii::$app->user->id);
$comment->content = Yii::$app->request->post('Comment')['content'];
if ($comment->save()) {
Yii::$app->session->setFlash('success', '评论成功');
return $this->redirect(['view', 'id' => $id]);
} else {
error_log(print_r($comment->errors, true));
Yii::$app->session->setFlash('error', '评论失败');
return $this->redirect(['view', 'id' => $id]);
}
}
$commentsProvider = new ActiveDataProvider(['query' => Comment::find()->where(['sugg_id' => $id])->orderBy('created_at DESC'), 'pagination' => ['pageSize' => 20]]);
return $this->render('view', ['model' => $this->findModel($id), 'comment' => $comment, 'commentsProvider' => $commentsProvider]);
}
开发者ID:dalinhuang,项目名称:wethepeople,代码行数:24,代码来源:SuggestionController.php
示例20: actionIndex
/**
* Displays homepage.
*
* @return mixed
*/
public function actionIndex()
{
$query = Page::find()->where(['live' => 1]);
$pagination = new Pagination(['defaultPageSize' => 2, 'totalCount' => $query->count()]);
$pages = $query->offset($pagination->offset)->limit($pagination->limit)->all();
$comments = Comment::getRecentComments();
$sidebarCategories = Category::getSidebarCategories();
$tags = Tag::getTagList();
return $this->render('index', ['pages' => $pages, 'pagination' => $pagination, 'comments' => $comments, 'sidebarCategories' => $sidebarCategories, 'tags' => $tags]);
}
开发者ID:BorisMatonickin,项目名称:yiicms,代码行数:15,代码来源:SiteController.php
注:本文中的common\models\Comment类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论