fastadmin 查看文章的评论

 

 1.js页面,添加按钮和事件

{
    name: 'evaluate',
    text: __('查看评论'),
    title: __('评论列表'),
    classname: 'btn btn-xs btn-info btn-evaluate',
    icon: 'fa fa-folder-o',
}
Table.api.events.operate=$.extend(Table.api.events.operate,{
    'click .btn-evaluate':function (e,value,row,index) {
        e.stopPropagation();
        e.preventDefault();
        var table=$(this).closest('table');
        var options=table.bootstrapTable('getOptions');
        var ids=row[options.pk];
        row=$.extend({},row?row:{},{ids:ids});
        var url=options.extend.evaluate_url+'?article_id='+row.id;
        Fast.api.open(Table.api.replaceurl(url,row,table),__('Evaluate'),$(this).data()||{});
    }
});

  

 2.控制器:

/
**
 * 查看
 */
public function index()
{
    //设置过滤方法
    $this->request->filter(['strip_tags']);
    if ($this->request->isAjax()) {
        //如果发送的来源是Selectpage,则转发到Selectpage
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        $article_id=$this->request->param('article_id');
        if($article_id){
            $where2=['article_id'=>['=',$article_id]];
        }else{
            $where2=1;
        }
        list($where, $sort, $order, $offset, $limit) = $this->buildparams();
        $total = $this->model
            ->with(["author","article"])
            ->where($where)
            ->where($where2)
            ->order($sort, $order)
            ->count();

        $list = $this->model
            ->with(["author","article"])
            ->where($where)
            ->where($where2)
            ->order($sort, $order)
            ->limit($offset, $limit)
            ->select();

        $list = collection($list)->toArray();
        $result = array("total" => $total, "rows" => $list);

        return json($result);
    }
    return $this->view->fetch();
}

 

posted @ 2020-07-12 18:11  CanyingV  阅读(287)  评论(0编辑  收藏  举报