完整代碼:
~~~
<?php
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文件。
也就是說 我們不需要后臺傳值
- php套路
- 套路之類結構
- thinkphp分塊解析之Collection
- thinkphp基礎之collection
- Collection在thinkphp中的運用
- thinkcmf模塊分析
- Controller按界面點擊順序排列表
- user模塊-Controller分析
- portal模塊-Controller分析
- admin模塊-Controller分析
- user模塊-腦圖
- portal模塊-腦圖
- admin模塊-腦圖
- cmf公共函數解析-common.php
- thinkcmf點滴記錄
- 自定義標簽詳解
- 插件
- 系統信息插件
- 插件演示插件
- 留言板插件
- 留言板1 建立胚胎
- 留言板1-1 數據庫變化
- 留言板1-2 自定義鉤子
- 留言板2 連接數據庫
- 留言板3 讀取后臺界面數據
- 留言板4 前端模板
- 留言板5 分離cssjs文件
- 留言板6 驗證
- 留言板7 圖形驗證碼
- 留言板8 后臺留言列表頁
- 留言板9 后記
- 評論插件
- 1 分析數據表
- 2 CommentModel.php
- 3 UserModel.php
- 4 DCommentPlugin.php
- 前端調用代碼
- 喜歡插件
- 1 分析
- 2 收藏功能
- 3 插件建模
- 4 數據庫設計
- 5 插入一條數據
- 多語言
- thinkphp多語言
- thinkcmf多語言