实习小结十五:关于post文章页面的小结(倒数第二篇)

来源:互联网 发布:免费中文域名注册 编辑:程序博客网 时间:2024/04/29 04:22

前段时间一直在做的post在admin中的页面,最近在top10inaction中的文章管理页面也做的差不多了~

先讲一下页面的点like功能,还是jquery做的,跟之前的权限管理其实差不多,html代码如下:

<div class="social-link-bar" id="link<?php echo $post->_id; ?>"><span class="social-links hide">    <a class="icon-link facebook" target="_blank" rel="nofollow" href="<?php echo $this->socialLink('facebook', $pageUrl, $metaTitle); ?>"></a>    <a class="icon-link google-plus" target="_blank" rel="nofollow" href="<?php echo $this->socialLink('google+', $pageUrl, $metaTitle); ?>"></a>    <a class="icon-link twitter" target="_blank" rel="nofollow" href="<?php echo $this->socialLink('twitter', $pageUrl, $metaTitle); ?>"></a>    <a class="icon-link linkedin" target="_blank" rel="nofollow" href="<?php echo $this->socialLink('linkedin', $pageUrl, $metaTitle); ?>"></a></span><a class="share-link link" href="javascript:void(0)"><?php echo $this->translate('Share') ?></a></div>

jquery代码如下:

$('#post .like-link.link').click(function(){        var postId = $(this).attr('id');            //console.log(postId);        window.likeProductButton = function() {            var button = $('#post .like-link.link#' + postId);            var action = button.hasClass('liked') ? 'unlike' : 'like';            $.get('/user/like/', {                object_id: postId,                content_type: 'post',                action: action            }, function(res) {                button.toggleClass('liked');                button.text(action == 'like' ? button.attr('LikedText') : button.attr('LikeText'));            });            $.get("/post/like/"+ postId +"/?action="+ action, function(ret){                console.log(action);                $(".under-title .liked").html("Liked( "+ret[1]+" )");            });        };    });

get函数之前有专门讲过,这个function是写在另外一个文件中,比较简单,就不贴了~

效果图如下:
当点击like按钮之后,变成红心,同时,左下角的liked数量也会发生变化。
这里写图片描述

另外,还遇到一个每次刷新都会请求重复提交表单的问题,我是这么解决的,当提交后,返回插入是否成功,若返回值为真,则重定向到当前网页。
代码如下:

$is_post = $request->isPost();$status = 0;if($is_post && !$status) {    $new = $request->getPost();    $new_review = new Review('post_review');    $new_review->title = $new->title;    $new_review->content = $new->content;    $new_review->reviewer_id = $user->id;    $new_review->reviewer_name = $user->username;    $new_review->product_id = $post->_id;    $status = $reviewCollection->addReview($new_review);}if($status){    $this->redirect()->toUrl('/post/'.$post_id);}

其他的也没什么特别难的了……时间跨度有点大,不太记得了…………

啊啊啊,今天是最后一天实习了……

0 0
原创粉丝点击