前段时间一直在做的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);
}
其他的也没什么特别难的了……时间跨度有点大,不太记得了…………
啊啊啊,今天是最后一天实习了……