完整代码:
~~~
namespace plugins\d_comment;
use cmf\lib\Plugin;
use plugins\d_comment\model\CommentModel;
class DCommentPlugin extends Plugin
{
public $info=[
'name'=>'DComment',
'title'=>'D之食卓评论插件',
'description'=>'基于官网评论插件',
'status'=>1,
'version'=>'1.0.0',
];
public $hasAdmin = 1;
public function install()
{
// TODO: Implement install() method.
return true;
}
public function uninstall()
{
// TODO: Implement uninstall() method.
return false;
}
public function dcomment($param)
{
$commentModel = new CommentModel();
$comment = $commentModel->where([
"table_name" => $param['table_name'],
"object_id" => $param['object_id'],
"status" => 1,
])
->order('create_time DESC')
->paginate(10,false,['var_page'=>'comment_page']);
$config = $this->getConfig();
$this->assign($config);
$this->assign('param', $param);
$this->assign('user', cmf_get_current_user());
$this->assign('page', $comment->render());
return $this->fetch('widget');
}
}
~~~
全是插件标准写法,现解析dcomment内容
table_name 评论内容挂载在哪个表下,如:portal_post
object_id 评论内容的id
仅仅用object_id不能定位唯一值,加上table_name就可以定位唯一了。这大大扩展了表的灵活性,使我们不仅仅局限于post一张表上
status 1为已审核
这里虽然写了config属性,但是其实我们并没有config文件。
也就是说 我们不需要后台传值