## 批量移動文章(用我的方式來完成之前框架未做好功能)
View: 搜索 '批量移動' 發現代碼是加了注釋的,先把注釋去掉:
> \themes\admin_simpleboot3\portal\admin_article\index.html
<button class="btn btn-primary btn-sm js-articles-move" type="button">批量移動</button>
同時需要修改底部的腳本。作者之前可能是想先獲取舊的欄目ID然后通過方法替換成新的ID。以下是用我的方法來實現,直接請求批量更新成為新的欄目ID就好。
//首先是實現彈窗的功能:
ids = ids.join(',');
url = '{:url("AdminArticle/move")}?ids='+ ids ;
art.dialog.open(url, {
// art.dialog.open("__ROOT__/index.php?g=portal&m=AdminArticle&a=move&old_term_id={$term.term_id|default=0}&ids=" + ids, {
title: "批量移動",
width: "400px",
close: function(){
reloadPage(window);
}
> \themes\admin_simpleboot3\portal\admin_article\move.html
新建move.html:頁面選擇分類以及IDS,然后將數據提交到moveSave()處理
<include file="public@header"/>
</head>
<body>
<div class="wrap">
<form method="post" class="js-ajax-form" action="{:url('AdminArticle/moveSave')}">
<div style="width: 350px">
<label style="width: 350px">分類:</label>
<select name="term_id" class="form-control" style="width: 280px;float: left;">
{$terms_tree}
</select>
<input type="hidden" name="ids" value="{$ids}">
<button class="btn btn-primary js-ajax-submit" type="submit" style="float: left;">移動</button>
</div>
</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>
> \app\portal\controller\AdminArticleController.php
控制器實現方法:
/**
* 批量移動彈出的窗口
* @return [view]
*/
public function move()
{
$param = $this->request->param();
$categoryId = $this->request->param('category', 0, 'intval');
//獲取欄目
$portalCategoryModel = new PortalCategoryModel();
$categoryTree = $portalCategoryModel->adminCategoryTree($categoryId);
$this->assign('terms_tree', $categoryTree);
//獲取IDS
$ids = $this->request->param('ids');
$this->assign('ids', $ids);
return $this->fetch();
}
/**
* 更新關系表的欄目ID
* @return [json]
*/
public function moveSave(){
$term_id = $this->request->param('term_id');
$ids = $this->request->param('ids');
Db::name('portal_category_post')->where('post_id', 'in', $ids)->update(['category_id' => $term_id]);
$this->success("移動成功!", '');
}
簡單粗暴的實現功能,希望有大神指點,提升一下水平。謝謝觀看!