关于日期插件My97 DatePicker与Think php模版标签冲突的解决方法
http://www.h-ui.net/H-ui.admin.shtml
common.js
function singwaapp_save(form) {
var data = $(form).serialize();
url = $(form).attr('url');
$.post(url, data, function (result) {
if (result.code == 0) {
layer.msg(result.msg, {icon: 5, time: 2000});
} else if (result.code == 1) {
self.location = result.data.jump_url;
}
}, 'JSON');
}
function selecttime(flag){
if(flag==1){
var endTime = $("#countTimeend").val();
if(endTime != ""){
WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',maxDate:endTime})}else{
WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})}
}else{
var startTime = $("#countTimestart").val();
if(startTime != ""){
WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',minDate:startTime})}else{
WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})}
}
}
News.php(Model)
'desc'];
$result = $this->where($data)
->order($order)
->paginate();
//调试
echo $this->getLastSql();
/**
* SELECT * FROM `ent_news` WHERE `status` <> -1 ORDER BY `id` desc LIMIT 0,3 <>
* SELECT * FROM `ent_news` WHERE `status` <> -1 ORDER BY `id` desc LIMIT 3,3 <>
*/
return $result;
}
/**
* 根据来获取列表的数据
* @param array $param
*/
public function getNewsByCondition($condition = [], $from = 0, $size = 5)
{
$condition['status'] = [
'neq', config('code.status_delete')];
$order = ['id' => 'desc'];
$result = $this->where($condition)
->limit($from, $size)
->order($order)
->select();
//SELECT * FROM `ent_news` WHERE `status` <> -1 ORDER BY `id` desc LIMIT 0,3
// echo $this->getLastSql();
return $result;
}
/**
* 根据条件来获取列表的数据的总数
* @param array $param
*/
public function getNewsCountCondition($condition = [])
{
$condition['status'] = [
'neq', config('code.status_delete')];
return $this->where($condition)
->count();
//SELECT COUNT(*) AS tp_count FROM `ent_news` WHERE `status` <> -1 LIMIT 1
//echo $this->getLastSql();
}
}
/**
* 根据来获取列表的数据
* @param array $param
*/
public function getNewsByCondition($condition = [], $from = 0, $size = 5)
{
$condition['status'] = [
'neq', config('code.status_delete')];
$order = ['id' => 'desc'];
$result = $this->where($condition)
->limit($from, $size)
->order($order)
->select();
//SELECT * FROM `ent_news` WHERE `status` <> -1 ORDER BY `id` desc LIMIT 0,3
// echo $this->getLastSql();
return $result;
}
/**
* 根据条件来获取列表的数据的总数
* @param array $param
*/
public function getNewsCountCondition($condition = [])
{
$condition['status'] = [
'neq', config('code.status_delete')];
return $this->where($condition)
->count();
//SELECT COUNT(*) AS tp_count FROM `ent_news` WHERE `status` <> -1 LIMIT 1
//echo $this->getLastSql();
}
Base.php(Controller)
isLogin();
if (!$isLogin) {
$this->redirect('login/index');
}
}
public function isLogin()
{
$user = session(config('admin.session_user'), '',
config('admin.session_user_scope'));
if ($user && $user->id) {
return true;
}
return false;
}
/**
* 获取分页page size内容
*/
public function getPageAndSize($data)
{
$this->page = !empty($data['page']) ? $data['page'] : 1;
$this->size = !empty($data['size']) ? $data['size'] : config('paginate.list_rows');
$this->from = ($this->page - 1) * $this->size;
}
}
News.php(Controller)
string '0' (length=1)
* 'start_time' => string '2017-10-02 14:23' (length=16)
* 'end_time' => string '2017-11-09 14:23' (length=16)
* 'title' => string '1233333' (length=7)
*/
//halt($data);
//转换查询条件
if (!empty($data['start_time']) &&
!empty($data['end_time']) &&
$data['end_time'] > $data['start_time']
) {
$whereData['create_time'] = [
['gt', strtotime($data['start_time'])],
['lt', strtotime($data['end_time'])],
];
}
if (!empty($data['catid'])) {
$whereData['catid'] = intval($data['catid']);
}
if (!empty($data['title'])) {
$whereData['title'] = [
'like', '%' . $data['title'] . '%'
];
}
$this->getPageAndSize($data);
//获取表里面的数据
$news = model('News')->getNewsByCondition($whereData, $this->from, $this->size);
//获取满足条件的数据总数=》有多少页
$total = model('News')->getNewsCountCondition($whereData);
//结合总数+size =>有多少页
//1.1=>2
$pageTotal = ceil($total / $this->size);
return $this->fetch('', [
'cats' => config('cat.list'),
'news' => $news,
'pageTotal' => $pageTotal,
'curr' => $this->page,
'start_time' => empty($data['start_time']) ? '' : $data['start_time'],
'end_time' => empty($data['end_time']) ? '' : $data['end_time'],
'catid' => empty($data['catid']) ? '' : $data['catid'],
'title' => empty($data['title']) ? '' : $data['title'],
'query'=>$query,
]);
}
public function add()
{
if (request()->isPost()) {
$data = input('post.');
try {
$id = model('News')->add($data);
} catch (\Exception $e) {
return $this->result('', 0, '新增失败:' . $e->getMessage());
}
if ($id) {
return $this->result([
'jump_url' => url('news/index')], 1, 'OK');
} else {
return $this->result('', 0, '新增失败');
}
} else {
return $this->fetch('', [
'cats' => config('cat.list')
]);
}
}
}
index.html(News)
{include file="public/_meta" title="娱乐资讯"/}
{include file="public/_footer" /}