http://layer.layui.com/ 官方下載地址
後臺彈出層關鍵代碼
common.php中的方法
獲取頁面中的 form表單。序列化後 ajax提交
js 頁面跳轉
js刪除操作
公共控制器方法
<?php
namespace Admin\Controller;
use Think\Controller;
/**
* use Common\Model 這塊可以不需要使用,框架默認會加載裏面的內容
*/
class CommonController extends Controller {
public function __construct() {
parent::__construct();
$this->_init();
}
/**
* 初始化
* @return
*/
private function _init() {
// 如果已經登錄
$isLogin = $this->isLogin();
if(!$isLogin) {
// 跳轉到登錄頁面
$this->redirect('/admin.php?c=login');
}
}
/**
* 獲取登錄用戶信息
* @return array
*/
public function getLoginUser() {
return session("adminUser");
}
/**
* 判定是否登錄
* @return boolean
*/
public function isLogin() {
$user = $this->getLoginUser();
if($user && is_array($user)) {
return true;
}
return false;
}
public function setStatus($data, $models) {
try {
if ($_POST) {
$id = $data['id'];
$status = $data['status'];
if (!$id) {
return show(0, 'ID不存在');
}
$res = D($models)->updateStatusById($id, $status);
if ($res) {
return show(1, '操作成功');
} else {
return show(0, '操作失敗');
}
}
return show(0, '沒有提交的內容');
}catch(Exception $e) {
return show(0, $e->getMessage());
}
}
public function listorder($model='') {
$listorder = $_POST['listorder'];
$jumpUrl = $_SERVER['HTTP_REFERER'];
$errors = array();
try {
if ($listorder) {
foreach ($listorder as $id => $v) {
// 執行更新
$id = D($model)->updateListorderById($id, $v);
if ($id === false) {
$errors[] = $id;
}
}
if ($errors) {
return show(0, '排序失敗-' . implode(',', $errors), array('jump_url' => $jumpUrl));
}
return show(1, '排序成功', array('jump_url' => $jumpUrl));
}
}catch (Exception $e) {
return show(0, $e->getMessage());
}
return show(0,'排序數據失敗',array('jump_url' => $jumpUrl));
}
}