<?php
namespace app\example\admin;
use app\system\admin\Admin;
use app\example\model\ExampleNews as NewsModel;
use app\example\model\ExampleCategory as CategoryModel;
use think\Db;
class Index extends Admin
{
protected $hisiModel = 'ExampleNews';
protected $hisiValidate = 'ExampleNews';
protected function initialize()
{
parent::initialize();
if ($this->request->action() != 'index' && !$this->request->isPost()) {
$category = CategoryModel::getSelect(CategoryModel::getChilds());
$this->assign('category', $category);
}
}
public function index()
{
if ($this->request->isAjax()) {
$where = $data = [];
$page = $this->request->param('page/d', 1);
$limit = $this->request->param('limit/d', 15);
$keyword = $this->request->param('keyword/s');
$cid = $this->request->param('cid/d');
if ($cid) {
$where[] = ['cid', '=', $cid];
}
if ($keyword) {
$where[] = ['title', 'like', '%'.$keyword.'%'];
}
$data['data'] = NewsModel::with('hasCategory')->where($where)->page($page)->limit($limit)->select();
$data['count'] = NewsModel::where($where)->count('id');
$data['code'] = 0;
return json($data);
}
$this->assign('hisiTabType', 0);
$this->assign('hisiTabData', '');
return $this->fetch();
}
}