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

前段时间一直在做的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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值