1、更新内核
2、代码格式化
This commit is contained in:
@@ -24,19 +24,19 @@
|
|||||||
* )
|
* )
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function int_to_string(&$data,$map=array('status'=>array(1=>'正常',-1=>'删除',0=>'禁用',2=>'未审核',3=>'草稿'))) {
|
function intToString(&$data, $map = array('status' => array(1 => '正常', -1 => '删除', 0 => '禁用', 2 => '未审核', 3 => '草稿'))) {
|
||||||
if($data === false || $data === null ){
|
if ($data === false || $data === null) {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
$data = (array)$data;
|
$data = (array) $data;
|
||||||
foreach ($data as $key => $row){
|
foreach ($data as $key => $row) {
|
||||||
foreach ($map as $col=>$pair){
|
foreach ($map as $col => $pair) {
|
||||||
if(isset($row[$col]) && isset($pair[$row[$col]])){
|
if (isset($row[$col]) && isset($pair[$row[$col]])) {
|
||||||
$data[$key][$col.'_text'] = $pair[$row[$col]];
|
$data[$key][$col . '_text'] = $pair[$row[$col]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,27 +45,36 @@ function int_to_string(&$data,$map=array('status'=>array(1=>'正常',-1=>'删除
|
|||||||
* @return string 状态文字 ,false 未获取到
|
* @return string 状态文字 ,false 未获取到
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function get_status_title($status = null){
|
function getStatusTitle($status = null) {
|
||||||
if(!isset($status)){
|
if (!isset($status)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch ($status){
|
switch ($status) {
|
||||||
case -1 : return '已删除'; break;
|
case -1:return '已删除';
|
||||||
case 0 : return '禁用'; break;
|
break;
|
||||||
case 1 : return '正常'; break;
|
case 0:return '禁用';
|
||||||
case 2 : return '待审核'; break;
|
break;
|
||||||
default : return false; break;
|
case 1:return '正常';
|
||||||
}
|
break;
|
||||||
|
case 2:return '待审核';
|
||||||
|
break;
|
||||||
|
default:return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取数据的状态操作
|
// 获取数据的状态操作
|
||||||
function show_status_op($status) {
|
function showStatusOp($status) {
|
||||||
switch ($status){
|
switch ($status) {
|
||||||
case 0 : return '启用'; break;
|
case 0:return '启用';
|
||||||
case 1 : return '禁用'; break;
|
break;
|
||||||
case 2 : return '审核'; break;
|
case 1:return '禁用';
|
||||||
default : return false; break;
|
break;
|
||||||
}
|
case 2:return '审核';
|
||||||
|
break;
|
||||||
|
default:return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,15 +83,15 @@ function show_status_op($status) {
|
|||||||
* @param bool $all 是否返回全部类型
|
* @param bool $all 是否返回全部类型
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function get_action_type($type, $all = false){
|
function getActionType($type, $all = false) {
|
||||||
$list = array(
|
$list = array(
|
||||||
1=>'系统',
|
1 => '系统',
|
||||||
2=>'用户',
|
2 => '用户',
|
||||||
);
|
);
|
||||||
if($all){
|
if ($all) {
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
return $list[$type];
|
return $list[$type];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,16 +100,16 @@ function get_action_type($type, $all = false){
|
|||||||
* @param string $field 需要获取的字段
|
* @param string $field 需要获取的字段
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function get_action($id = null, $field = null){
|
function getAction($id = null, $field = null) {
|
||||||
if(empty($id) && !is_numeric($id)){
|
if (empty($id) && !is_numeric($id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$list = cache('action_list');
|
$list = cache('action_list');
|
||||||
if(empty($list[$id])){
|
if (empty($list[$id])) {
|
||||||
$map = array('status'=>array('gt', -1), 'id'=>$id);
|
$map = array('status' => array('gt', -1), 'id' => $id);
|
||||||
$list[$id] = db('Action')->where($map)->field(true)->find();
|
$list[$id] = db('Action')->where($map)->field(true)->find();
|
||||||
}
|
}
|
||||||
return empty($field) ? $list[$id] : $list[$id][$field];
|
return empty($field) ? $list[$id] : $list[$id][$field];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,18 +119,18 @@ function get_action($id = null, $field = null){
|
|||||||
* @param string $field 需要返回的字段,不传则返回整个数据
|
* @param string $field 需要返回的字段,不传则返回整个数据
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
function get_document_field($value = null, $condition = 'id', $field = null){
|
function getDocumentField($value = null, $condition = 'id', $field = null) {
|
||||||
if(empty($value)){
|
if (empty($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//拼接参数
|
//拼接参数
|
||||||
$map[$condition] = $value;
|
$map[$condition] = $value;
|
||||||
$info = db('Model')->where($map);
|
$info = db('Model')->where($map);
|
||||||
if(empty($field)){
|
if (empty($field)) {
|
||||||
$info = $info->field(true)->find();
|
$info = $info->field(true)->find();
|
||||||
}else{
|
} else {
|
||||||
$info = $info->value($field);
|
$info = $info->value($field);
|
||||||
}
|
}
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,27 +14,27 @@ class Addons extends Admin {
|
|||||||
|
|
||||||
protected $addons;
|
protected $addons;
|
||||||
|
|
||||||
public function _initialize(){
|
public function _initialize() {
|
||||||
parent::_initialize();
|
parent::_initialize();
|
||||||
//加入菜单
|
//加入菜单
|
||||||
$this->getAddonsMenu();
|
$this->getAddonsMenu();
|
||||||
$this->addons = model('Addons');
|
$this->addons = model('Addons');
|
||||||
$this->hooks = db('Hooks');
|
$this->hooks = db('Hooks');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 插件列表
|
* 插件列表
|
||||||
*/
|
*/
|
||||||
public function index($refresh = 0){
|
public function index($refresh = 0) {
|
||||||
if ($refresh) {
|
if ($refresh) {
|
||||||
$this->addons->refresh();
|
$this->addons->refresh();
|
||||||
}
|
}
|
||||||
$list = $this->addons->order('id desc')->paginate(25);
|
$list = $this->addons->order('id desc')->paginate(25);
|
||||||
// 记录当前列表页的cookie
|
// 记录当前列表页的cookie
|
||||||
Cookie('__forward__',$_SERVER['REQUEST_URI']);
|
Cookie('__forward__', $_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'list' => $list,
|
'list' => $list,
|
||||||
'page' => $list->render()
|
'page' => $list->render(),
|
||||||
);
|
);
|
||||||
$this->setMeta("插件管理");
|
$this->setMeta("插件管理");
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
@@ -42,27 +42,27 @@ class Addons extends Admin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//创建向导首页
|
//创建向导首页
|
||||||
public function add(){
|
public function add() {
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$data = $this->addons->create();
|
$data = $this->addons->create();
|
||||||
if ($data) {
|
if ($data) {
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success("创建成功!",url('admin/addons/index'));
|
return $this->success("创建成功!", url('admin/addons/index'));
|
||||||
}else{
|
} else {
|
||||||
return $this->error("创建失败!");
|
return $this->error("创建失败!");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
return $this->error($this->addons->getError());
|
return $this->error($this->addons->getError());
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$hooks = db('Hooks')->field('name,description')->select();
|
$hooks = db('Hooks')->field('name,description')->select();
|
||||||
$this->assign('Hooks',$hooks);
|
$this->assign('Hooks', $hooks);
|
||||||
$hook = db('Hooks')->field(true)->select();
|
$hook = db('Hooks')->field(true)->select();
|
||||||
foreach($hook as $key => $value){
|
foreach ($hook as $key => $value) {
|
||||||
$addons_opt[$value['name']] = $value['name'];
|
$addons_opt[$value['name']] = $value['name'];
|
||||||
}
|
}
|
||||||
$addons_opt = array(array('type'=>'select','opt'=>$addons_opt));
|
$addons_opt = array(array('type' => 'select', 'opt' => $addons_opt));
|
||||||
if(!is_writable(SENT_ADDON_PATH)){
|
if (!is_writable(SENT_ADDON_PATH)) {
|
||||||
return $this->error('您没有创建目录写入权限,无法使用此功能');
|
return $this->error('您没有创建目录写入权限,无法使用此功能');
|
||||||
}
|
}
|
||||||
$this->setMeta("添加插件");
|
$this->setMeta("添加插件");
|
||||||
@@ -71,35 +71,35 @@ class Addons extends Admin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//预览
|
//预览
|
||||||
public function preview($output = true){
|
public function preview($output = true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 安装插件
|
* 安装插件
|
||||||
*/
|
*/
|
||||||
public function install(){
|
public function install() {
|
||||||
$addon_name = input('addon_name','','trim,ucfirst');
|
$addon_name = input('addon_name', '', 'trim,ucfirst');
|
||||||
$class = get_addon_class($addon_name);
|
$class = get_addon_class($addon_name);
|
||||||
if(class_exists($class)){
|
if (class_exists($class)) {
|
||||||
$addons = new $class;
|
$addons = new $class;
|
||||||
$info = $addons->info;
|
$info = $addons->info;
|
||||||
if(!$info || !$addons->checkInfo()){
|
if (!$info || !$addons->checkInfo()) {
|
||||||
//检测信息的正确性
|
//检测信息的正确性
|
||||||
return $this->error('插件信息缺失');
|
return $this->error('插件信息缺失');
|
||||||
}
|
}
|
||||||
session('addons_install_error',null);
|
session('addons_install_error', null);
|
||||||
$install_flag = $addons->install();
|
$install_flag = $addons->install();
|
||||||
if(!$install_flag){
|
if (!$install_flag) {
|
||||||
return $this->error('执行插件预安装操作失败'.session('addons_install_error'));
|
return $this->error('执行插件预安装操作失败' . session('addons_install_error'));
|
||||||
}
|
}
|
||||||
$result = $this->addons->install($info);
|
$result = $this->addons->install($info);
|
||||||
if($result){
|
if ($result) {
|
||||||
cache('hooks', null);
|
cache('hooks', null);
|
||||||
return $this->success('安装成功');
|
return $this->success('安装成功');
|
||||||
}else{
|
} else {
|
||||||
return $this->error($this->addons->getError());
|
return $this->error($this->addons->getError());
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
return $this->error('插件不存在');
|
return $this->error('插件不存在');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,11 +107,11 @@ class Addons extends Admin {
|
|||||||
/**
|
/**
|
||||||
* 卸载插件
|
* 卸载插件
|
||||||
*/
|
*/
|
||||||
public function uninstall($id){
|
public function uninstall($id) {
|
||||||
$result = $this->addons->uninstall($id);
|
$result = $this->addons->uninstall($id);
|
||||||
if($result === false){
|
if ($result === false) {
|
||||||
return $this->error($this->addons->getError(),'');
|
return $this->error($this->addons->getError(), '');
|
||||||
}else{
|
} else {
|
||||||
return $this->success('卸载成功!');
|
return $this->success('卸载成功!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,14 +119,14 @@ class Addons extends Admin {
|
|||||||
/**
|
/**
|
||||||
* 启用插件
|
* 启用插件
|
||||||
*/
|
*/
|
||||||
public function enable(){
|
public function enable() {
|
||||||
$id = input('id');
|
$id = input('id');
|
||||||
cache('hooks', null);
|
cache('hooks', null);
|
||||||
$model = model('Addons');
|
$model = model('Addons');
|
||||||
$result = $model::where(array('id'=>$id))->update(array('status'=>1));
|
$result = $model::where(array('id' => $id))->update(array('status' => 1));
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success('启用成功');
|
return $this->success('启用成功');
|
||||||
}else{
|
} else {
|
||||||
return $this->error("启用失败!");
|
return $this->error("启用失败!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,14 +134,14 @@ class Addons extends Admin {
|
|||||||
/**
|
/**
|
||||||
* 禁用插件
|
* 禁用插件
|
||||||
*/
|
*/
|
||||||
public function disable(){
|
public function disable() {
|
||||||
$id = input('id');
|
$id = input('id');
|
||||||
cache('hooks', null);
|
cache('hooks', null);
|
||||||
$model = model('Addons');
|
$model = model('Addons');
|
||||||
$result = $model::where(array('id'=>$id))->update(array('status'=>0));
|
$result = $model::where(array('id' => $id))->update(array('status' => 0));
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success('禁用成功');
|
return $this->success('禁用成功');
|
||||||
}else{
|
} else {
|
||||||
return $this->error("禁用失败!");
|
return $this->error("禁用失败!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,11 +149,11 @@ class Addons extends Admin {
|
|||||||
/**
|
/**
|
||||||
* 设置插件页面
|
* 设置插件页面
|
||||||
*/
|
*/
|
||||||
public function config(){
|
public function config() {
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
# code...
|
# code...
|
||||||
}else{
|
} else {
|
||||||
$id = input('id','','trim,intval');
|
$id = input('id', '', 'trim,intval');
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
return $this->error("非法操作!");
|
return $this->error("非法操作!");
|
||||||
}
|
}
|
||||||
@@ -162,13 +162,13 @@ class Addons extends Admin {
|
|||||||
$class = get_addon_class($info['name']);
|
$class = get_addon_class($info['name']);
|
||||||
|
|
||||||
$keyList = array();
|
$keyList = array();
|
||||||
$data = array(
|
$data = array(
|
||||||
'keyList' => $keyList
|
'keyList' => $keyList,
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
$this->setMeta($info['title'] . " - 设置");
|
$this->setMeta($info['title'] . " - 设置");
|
||||||
return $this->fetch('public/edit');
|
return $this->fetch('public/edit');
|
||||||
}else{
|
} else {
|
||||||
return $this->error("未安装此插件!");
|
return $this->error("未安装此插件!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,17 +180,17 @@ class Addons extends Admin {
|
|||||||
* @param string $addons 插件名称
|
* @param string $addons 插件名称
|
||||||
* @param string $addons 插件简介
|
* @param string $addons 插件简介
|
||||||
*/
|
*/
|
||||||
public function existHook($str, $addons, $msg=''){
|
public function existHook($str, $addons, $msg = '') {
|
||||||
$hook_mod = db('Hooks');
|
$hook_mod = db('Hooks');
|
||||||
$where['name'] = $str;
|
$where['name'] = $str;
|
||||||
$gethook = $hook_mod->where($where)->find();
|
$gethook = $hook_mod->where($where)->find();
|
||||||
if(!$gethook || empty($gethook) || !is_array($gethook)){
|
if (!$gethook || empty($gethook) || !is_array($gethook)) {
|
||||||
$data['name'] = $str;
|
$data['name'] = $str;
|
||||||
$data['description'] = $msg;
|
$data['description'] = $msg;
|
||||||
$data['type'] = 1;
|
$data['type'] = 1;
|
||||||
$data['update_time'] = time();
|
$data['update_time'] = time();
|
||||||
$data['addons'] = $addons;
|
$data['addons'] = $addons;
|
||||||
if( false !== $hook_mod->create($data) ){
|
if (false !== $hook_mod->create($data)) {
|
||||||
$hook_mod->add();
|
$hook_mod->add();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,8 +200,8 @@ class Addons extends Admin {
|
|||||||
* 删除钩子
|
* 删除钩子
|
||||||
* @param string $hook 钩子名称
|
* @param string $hook 钩子名称
|
||||||
*/
|
*/
|
||||||
public function deleteHook($hook){
|
public function deleteHook($hook) {
|
||||||
$model = db('hooks');
|
$model = db('hooks');
|
||||||
$condition = array(
|
$condition = array(
|
||||||
'name' => $hook,
|
'name' => $hook,
|
||||||
);
|
);
|
||||||
@@ -212,36 +212,36 @@ class Addons extends Admin {
|
|||||||
/**
|
/**
|
||||||
* 钩子列表
|
* 钩子列表
|
||||||
*/
|
*/
|
||||||
public function hooks(){
|
public function hooks() {
|
||||||
|
|
||||||
$map = array();
|
$map = array();
|
||||||
$order = "id desc";
|
$order = "id desc";
|
||||||
$list = model('Hooks')->where($map)->order($order)->paginate(10);
|
$list = model('Hooks')->where($map)->order($order)->paginate(10);
|
||||||
|
|
||||||
// 记录当前列表页的cookie
|
// 记录当前列表页的cookie
|
||||||
Cookie('__forward__',$_SERVER['REQUEST_URI']);
|
Cookie('__forward__', $_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'list' => $list,
|
'list' => $list,
|
||||||
'page' => $list->render()
|
'page' => $list->render(),
|
||||||
);
|
);
|
||||||
$this->setMeta("钩子管理");
|
$this->setMeta("钩子管理");
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addhook(){
|
public function addhook() {
|
||||||
$hooks = model('Hooks');
|
$hooks = model('Hooks');
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$result = $hooks->change();
|
$result = $hooks->change();
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
return $this->success("修改成功");
|
return $this->success("修改成功");
|
||||||
}else{
|
} else {
|
||||||
return $this->error($hooks->getError());
|
return $this->error($hooks->getError());
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$keylist = $hooks->getaddons();
|
$keylist = $hooks->getaddons();
|
||||||
$data = array(
|
$data = array(
|
||||||
'keyList' => $keylist,
|
'keyList' => $keylist,
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
@@ -251,20 +251,20 @@ class Addons extends Admin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//钩子出编辑挂载插件页面
|
//钩子出编辑挂载插件页面
|
||||||
public function edithook($id){
|
public function edithook($id) {
|
||||||
$hooks = model('Hooks');
|
$hooks = model('Hooks');
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$result = $hooks->change();
|
$result = $hooks->change();
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
return $this->success("修改成功");
|
return $this->success("修改成功");
|
||||||
}else{
|
} else {
|
||||||
return $this->error($hooks->getError());
|
return $this->error($hooks->getError());
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$info = db('Hooks')->find($id);
|
$info = db('Hooks')->find($id);
|
||||||
$keylist = $hooks->getaddons($info['addons']);
|
$keylist = $hooks->getaddons($info['addons']);
|
||||||
$data = array(
|
$data = array(
|
||||||
'info' => $info,
|
'info' => $info,
|
||||||
'keyList' => $keylist,
|
'keyList' => $keylist,
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
@@ -274,41 +274,41 @@ class Addons extends Admin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//超级管理员删除钩子
|
//超级管理员删除钩子
|
||||||
public function delhook(){
|
public function delhook() {
|
||||||
$id = input('id','','trim,intval');
|
$id = input('id', '', 'trim,intval');
|
||||||
$ids = input('post.ids/a',array());
|
$ids = input('post.ids/a', array());
|
||||||
array_push($ids, $id);
|
array_push($ids, $id);
|
||||||
$map['id'] = array('IN',$ids);
|
$map['id'] = array('IN', $ids);
|
||||||
$result = $this->hooks->where($map)->delete();
|
$result = $this->hooks->where($map)->delete();
|
||||||
if($result !== false){
|
if ($result !== false) {
|
||||||
return $this->success('删除成功');
|
return $this->success('删除成功');
|
||||||
}else{
|
} else {
|
||||||
return $this->error('删除失败');
|
return $this->error('删除失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateHook(){
|
public function updateHook() {
|
||||||
$hookModel = D('Hooks');
|
$hookModel = D('Hooks');
|
||||||
$data = $hookModel->create();
|
$data = $hookModel->create();
|
||||||
if($data){
|
if ($data) {
|
||||||
if($data['id']){
|
if ($data['id']) {
|
||||||
$flag = $hookModel->save($data);
|
$flag = $hookModel->save($data);
|
||||||
if($flag !== false){
|
if ($flag !== false) {
|
||||||
S('hooks', null);
|
S('hooks', null);
|
||||||
$this->success('更新成功', Cookie('__forward__'));
|
$this->success('更新成功', Cookie('__forward__'));
|
||||||
}else{
|
} else {
|
||||||
$this->error('更新失败');
|
$this->error('更新失败');
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$flag = $hookModel->add($data);
|
$flag = $hookModel->add($data);
|
||||||
if($flag){
|
if ($flag) {
|
||||||
S('hooks', null);
|
S('hooks', null);
|
||||||
$this->success('新增成功', Cookie('__forward__'));
|
$this->success('新增成功', Cookie('__forward__'));
|
||||||
}else{
|
} else {
|
||||||
$this->error('新增失败');
|
$this->error('新增失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$this->error($hookModel->getError());
|
$this->error($hookModel->getError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -10,96 +10,96 @@
|
|||||||
return array(
|
return array(
|
||||||
|
|
||||||
// 调试模式
|
// 调试模式
|
||||||
'app_debug' => true,
|
'app_debug' => true,
|
||||||
|
|
||||||
'charset' => 'UTF-8',
|
'charset' => 'UTF-8',
|
||||||
'lang_switch_on' => true, // 开启语言包功能
|
'lang_switch_on' => true, // 开启语言包功能
|
||||||
'lang_list' => ['zh-cn'], // 支持的语言列表
|
'lang_list' => ['zh-cn'], // 支持的语言列表
|
||||||
|
|
||||||
'data_auth_key' => 'sent',
|
'data_auth_key' => 'sent',
|
||||||
|
|
||||||
'base_url' => BASE_PATH,
|
'base_url' => BASE_PATH,
|
||||||
'url_route_on' => true,
|
'url_route_on' => true,
|
||||||
'url_common_param' => false,
|
'url_common_param' => false,
|
||||||
|
|
||||||
'template' => array(
|
'template' => array(
|
||||||
'taglib_build_in' => 'cx,com\Sent'
|
'taglib_build_in' => 'cx,com\Sent',
|
||||||
),
|
),
|
||||||
|
|
||||||
// 'dispatch_success_tmpl' => APP_PATH . 'common/view/default/jump.html',
|
// 'dispatch_success_tmpl' => APP_PATH . 'common/view/default/jump.html',
|
||||||
// 'dispatch_error_tmpl' => APP_PATH . 'common/view/default/jump.html',
|
// 'dispatch_error_tmpl' => APP_PATH . 'common/view/default/jump.html',
|
||||||
|
|
||||||
'attachment_upload' => array(
|
'attachment_upload' => array(
|
||||||
// 允许上传的文件MiMe类型
|
// 允许上传的文件MiMe类型
|
||||||
'mimes' => [],
|
'mimes' => [],
|
||||||
// 上传的文件大小限制 (0-不做限制)
|
// 上传的文件大小限制 (0-不做限制)
|
||||||
'maxSize' => 0,
|
'maxSize' => 0,
|
||||||
// 允许上传的文件后缀
|
// 允许上传的文件后缀
|
||||||
'exts' => [],
|
'exts' => [],
|
||||||
// 子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组
|
// 子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组
|
||||||
'subName' => ['date', 'Ymd'],
|
'subName' => ['date', 'Ymd'],
|
||||||
//保存根路径
|
//保存根路径
|
||||||
'rootPath' => './uploads/attachment',
|
'rootPath' => './uploads/attachment',
|
||||||
// 保存路径
|
// 保存路径
|
||||||
'savePath' => '',
|
'savePath' => '',
|
||||||
// 上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组
|
// 上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组
|
||||||
'saveName' => ['uniqid', ''],
|
'saveName' => ['uniqid', ''],
|
||||||
// 文件上传驱动e,
|
// 文件上传驱动e,
|
||||||
'driver' => 'Local',
|
'driver' => 'Local',
|
||||||
),
|
),
|
||||||
|
|
||||||
'editor_upload' => array(
|
'editor_upload' => array(
|
||||||
// 允许上传的文件MiMe类型
|
// 允许上传的文件MiMe类型
|
||||||
'mimes' => [],
|
'mimes' => [],
|
||||||
// 上传的文件大小限制 (0-不做限制)
|
// 上传的文件大小限制 (0-不做限制)
|
||||||
'maxSize' => 0,
|
'maxSize' => 0,
|
||||||
// 允许上传的文件后缀
|
// 允许上传的文件后缀
|
||||||
'exts' => [],
|
'exts' => [],
|
||||||
// 子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组
|
// 子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组
|
||||||
'subName' => ['date', 'Ymd'],
|
'subName' => ['date', 'Ymd'],
|
||||||
//保存根路径
|
//保存根路径
|
||||||
'rootPath' => './uploads/editor',
|
'rootPath' => './uploads/editor',
|
||||||
// 保存路径
|
// 保存路径
|
||||||
'savePath' => '',
|
'savePath' => '',
|
||||||
// 上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组
|
// 上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组
|
||||||
'saveName' => ['uniqid', ''],
|
'saveName' => ['uniqid', ''],
|
||||||
// 文件上传驱动e,
|
// 文件上传驱动e,
|
||||||
'driver' => 'Local',
|
'driver' => 'Local',
|
||||||
),
|
),
|
||||||
|
|
||||||
'picture_upload' => array(
|
'picture_upload' => array(
|
||||||
// 允许上传的文件MiMe类型
|
// 允许上传的文件MiMe类型
|
||||||
'mimes' => [],
|
'mimes' => [],
|
||||||
// 上传的文件大小限制 (0-不做限制)
|
// 上传的文件大小限制 (0-不做限制)
|
||||||
'maxSize' => 0,
|
'maxSize' => 0,
|
||||||
// 允许上传的文件后缀
|
// 允许上传的文件后缀
|
||||||
'exts' => [],
|
'exts' => [],
|
||||||
// 子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组
|
// 子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组
|
||||||
'subName' => ['date', 'Ymd'],
|
'subName' => ['date', 'Ymd'],
|
||||||
//保存根路径
|
//保存根路径
|
||||||
'rootPath' => './uploads/picture',
|
'rootPath' => './uploads/picture',
|
||||||
// 保存路径
|
// 保存路径
|
||||||
'savePath' => '',
|
'savePath' => '',
|
||||||
// 上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组
|
// 上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组
|
||||||
'saveName' => ['uniqid', ''],
|
'saveName' => ['uniqid', ''],
|
||||||
// 文件上传驱动e,
|
// 文件上传驱动e,
|
||||||
'driver' => 'Local',
|
'driver' => 'Local',
|
||||||
),
|
),
|
||||||
'session' => array(
|
'session' => array(
|
||||||
'prefix' => 'sent',
|
'prefix' => 'sent',
|
||||||
'type' => '',
|
'type' => '',
|
||||||
'auto_start' => true,
|
'auto_start' => true,
|
||||||
),
|
),
|
||||||
|
|
||||||
'log' => array(
|
'log' => array(
|
||||||
// 日志记录方式,支持 file sae
|
// 日志记录方式,支持 file sae
|
||||||
'type' => 'file',
|
'type' => 'file',
|
||||||
// 日志保存目录
|
// 日志保存目录
|
||||||
'path' => LOG_PATH,
|
'path' => LOG_PATH,
|
||||||
),
|
),
|
||||||
// 页面Trace信息
|
// 页面Trace信息
|
||||||
'trace' =>array(
|
'trace' => array(
|
||||||
//支持Html,Console 设为false则不显示
|
//支持Html,Console 设为false则不显示
|
||||||
'type' => 'Html',
|
'type' => 'Html',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -8,34 +8,34 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'__pattern__' => array(
|
'__pattern__' => array(
|
||||||
'name' => '\w+',
|
'name' => '\w+',
|
||||||
),
|
),
|
||||||
|
|
||||||
'/' => 'index/index/index', // 首页访问路由
|
'/' => 'index/index/index', // 首页访问路由
|
||||||
'search' => 'index/search/index', // 首页访问路由
|
'search' => 'index/search/index', // 首页访问路由
|
||||||
|
|
||||||
'cart/index' => 'index/cart/index',
|
'cart/index' => 'index/cart/index',
|
||||||
'cart/add' => 'index/cart/add',
|
'cart/add' => 'index/cart/add',
|
||||||
'cart/count' => 'index/cart/count',
|
'cart/count' => 'index/cart/count',
|
||||||
|
|
||||||
'login' => 'user/login/index',
|
'login' => 'user/login/index',
|
||||||
'register' => 'user/login/register',
|
'register' => 'user/login/register',
|
||||||
'logout' => 'user/login/logout',
|
'logout' => 'user/login/logout',
|
||||||
'uc' => 'user/index/index',
|
'uc' => 'user/index/index',
|
||||||
|
|
||||||
'order/index' => 'user/order/index',
|
'order/index' => 'user/order/index',
|
||||||
'order/list' => 'user/order/lists',
|
'order/list' => 'user/order/lists',
|
||||||
|
|
||||||
'admin/login' => 'admin/index/login',
|
'admin/login' => 'admin/index/login',
|
||||||
'admin/logout' => 'admin/index/logout',
|
'admin/logout' => 'admin/index/logout',
|
||||||
|
|
||||||
// 变量传入index模块的控制器和操作方法
|
// 变量传入index模块的控制器和操作方法
|
||||||
'addons/:mc/:ac' => 'index/addons/execute', // 静态地址和动态地址结合
|
'addons/:mc/:ac' => 'index/addons/execute', // 静态地址和动态地址结合
|
||||||
'usera/:mc/:ac' => 'user/addons/execute', // 静态地址和动态地址结合
|
'usera/:mc/:ac' => 'user/addons/execute', // 静态地址和动态地址结合
|
||||||
'admina/:mc/:ac' => 'admin/addons/execute', // 静态地址和动态地址结合
|
'admina/:mc/:ac' => 'admin/addons/execute', // 静态地址和动态地址结合
|
||||||
|
|
||||||
'book/list' => 'index/book/index',
|
'book/list' => 'index/book/index',
|
||||||
'book/search' => 'index/book/search',
|
'book/search' => 'index/book/search',
|
||||||
'book/detail/:id' => 'index/book/detail',
|
'book/detail/:id' => 'index/book/detail',
|
||||||
);
|
);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
return array(
|
return array(
|
||||||
'app_init' => array('app\\common\\behavior\\InitHook'),
|
'app_init' => array('app\\common\\behavior\\InitHook'),
|
||||||
);
|
);
|
||||||
@@ -10,51 +10,51 @@
|
|||||||
namespace app\user\controller;
|
namespace app\user\controller;
|
||||||
use app\common\controller\User;
|
use app\common\controller\User;
|
||||||
|
|
||||||
class Content extends User{
|
class Content extends User {
|
||||||
|
|
||||||
public function _initialize(){
|
public function _initialize() {
|
||||||
parent::_initialize();
|
parent::_initialize();
|
||||||
$this->getContentMenu();
|
$this->getContentMenu();
|
||||||
$model_id = $this->request->param('model_id');
|
$model_id = $this->request->param('model_id');
|
||||||
$row = db('Model')->select();
|
$row = db('Model')->select();
|
||||||
foreach ($row as $key => $value) {
|
foreach ($row as $key => $value) {
|
||||||
$list[$value['id']] = $value;
|
$list[$value['id']] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($list[$model_id])) {
|
if (empty($list[$model_id])) {
|
||||||
return $this->error("无此模型!");
|
return $this->error("无此模型!");
|
||||||
}else {
|
} else {
|
||||||
$this->modelInfo = $list[$model_id];
|
$this->modelInfo = $list[$model_id];
|
||||||
if ($this->modelInfo['extend'] > 1) {
|
if ($this->modelInfo['extend'] > 1) {
|
||||||
$this->model = model($this->modelInfo['name']);
|
$this->model = model($this->modelInfo['name']);
|
||||||
}else{
|
} else {
|
||||||
$this->model = model('Document')->extend($this->modelInfo['name']);
|
$this->model = model('Document')->extend($this->modelInfo['name']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assign('model_id',$model_id);
|
$this->assign('model_id', $model_id);
|
||||||
$this->assign('model_list',$list);
|
$this->assign('model_list', $list);
|
||||||
$this->assign('model_info',$this->modelInfo);
|
$this->assign('model_info', $this->modelInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(){
|
public function index() {
|
||||||
if ($this->modelInfo['list_grid'] == '') {
|
if ($this->modelInfo['list_grid'] == '') {
|
||||||
return $this->error("列表定义不正确!", url('admin/model/edit',array('id'=>$this->modelInfo['id'])));
|
return $this->error("列表定义不正确!", url('admin/model/edit', array('id' => $this->modelInfo['id'])));
|
||||||
}
|
}
|
||||||
$grid_list = get_grid_list($this->modelInfo['list_grid']);
|
$grid_list = get_grid_list($this->modelInfo['list_grid']);
|
||||||
$order = "id desc";
|
$order = "id desc";
|
||||||
$map['uid'] = session('user_auth.uid');
|
$map['uid'] = session('user_auth.uid');
|
||||||
if ($this->modelInfo['extend'] == 1) {
|
if ($this->modelInfo['extend'] == 1) {
|
||||||
$map['model_id'] = $this->modelInfo['id'];
|
$map['model_id'] = $this->modelInfo['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$field = array_filter($grid_list['fields']);
|
$field = array_filter($grid_list['fields']);
|
||||||
$list = $this->model->where($map)->field($field)->order($order)->paginate(15);
|
$list = $this->model->where($map)->field($field)->order($order)->paginate(15);
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'grid' => $grid_list,
|
'grid' => $grid_list,
|
||||||
'list' => $list,
|
'list' => $list,
|
||||||
'page' => $list->render()
|
'page' => $list->render(),
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
@@ -64,21 +64,21 @@ class Content extends User{
|
|||||||
* 内容添加
|
* 内容添加
|
||||||
* @author molong <ycgpp@126.com>
|
* @author molong <ycgpp@126.com>
|
||||||
*/
|
*/
|
||||||
public function add(){
|
public function add() {
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$result = $this->model->change();
|
$result = $this->model->change();
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success("添加成功!",url('admin/content/index',array('model_id'=>$this->modelInfo['id'])));
|
return $this->success("添加成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
|
||||||
}else{
|
} else {
|
||||||
return $this->error($this->model->getError(),'');
|
return $this->error($this->model->getError(), '');
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
$info = array(
|
$info = array(
|
||||||
'model_id' => $this->modelInfo['id']
|
'model_id' => $this->modelInfo['id'],
|
||||||
);
|
);
|
||||||
$data = array(
|
$data = array(
|
||||||
'info' => $info,
|
'info' => $info,
|
||||||
'fieldGroup' => $this->getField($this->modelInfo)
|
'fieldGroup' => $this->getField($this->modelInfo),
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
return $this->fetch('public/edit');
|
return $this->fetch('public/edit');
|
||||||
@@ -89,15 +89,15 @@ class Content extends User{
|
|||||||
* 内容修改
|
* 内容修改
|
||||||
* @author molong <ycgpp@126.com>
|
* @author molong <ycgpp@126.com>
|
||||||
*/
|
*/
|
||||||
public function edit($id){
|
public function edit($id) {
|
||||||
if (IS_POST) {
|
if (IS_POST) {
|
||||||
$result = $this->model->change();
|
$result = $this->model->change();
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
return $this->success("更新成功!",url('admin/content/index',array('model_id'=>$this->modelInfo['id'])));
|
return $this->success("更新成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
|
||||||
}else{
|
} else {
|
||||||
return $this->error($this->model->getError(),'');
|
return $this->error($this->model->getError(), '');
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
return $this->error("非法操作!");
|
return $this->error("非法操作!");
|
||||||
}
|
}
|
||||||
@@ -106,9 +106,9 @@ class Content extends User{
|
|||||||
return $this->error($this->model->getError());
|
return $this->error($this->model->getError());
|
||||||
}
|
}
|
||||||
$info['model_id'] = $this->modelInfo['id'];
|
$info['model_id'] = $this->modelInfo['id'];
|
||||||
$data = array(
|
$data = array(
|
||||||
'info' => $info,
|
'info' => $info,
|
||||||
'fieldGroup' => $this->getField($this->modelInfo)
|
'fieldGroup' => $this->getField($this->modelInfo),
|
||||||
);
|
);
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
return $this->fetch('public/edit');
|
return $this->fetch('public/edit');
|
||||||
@@ -119,44 +119,44 @@ class Content extends User{
|
|||||||
* 内容删除
|
* 内容删除
|
||||||
* @author molong <ycgpp@126.com>
|
* @author molong <ycgpp@126.com>
|
||||||
*/
|
*/
|
||||||
public function del(){
|
public function del() {
|
||||||
$id = input('get.id','','trim');
|
$id = input('get.id', '', 'trim');
|
||||||
$ids = input('post.ids/a',array());
|
$ids = input('post.ids/a', array());
|
||||||
array_push($ids, $id);
|
array_push($ids, $id);
|
||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return $this->error("非法操作!");
|
return $this->error("非法操作!");
|
||||||
}
|
}
|
||||||
|
|
||||||
$map['id'] = array('IN',$ids);
|
$map['id'] = array('IN', $ids);
|
||||||
$result = $this->model->del($map);
|
$result = $this->model->del($map);
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success("删除成功!");
|
return $this->success("删除成功!");
|
||||||
}else{
|
} else {
|
||||||
return $this->error("删除失败!", '', "");
|
return $this->error("删除失败!", '', "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getField(){
|
protected function getField() {
|
||||||
$field_group = parse_config_attr($this->modelInfo['field_group']);
|
$field_group = parse_config_attr($this->modelInfo['field_group']);
|
||||||
$field_sort = json_decode($this->modelInfo['field_sort'],true);
|
$field_sort = json_decode($this->modelInfo['field_sort'], true);
|
||||||
|
|
||||||
if ($this->modelInfo['extend'] > 1) {
|
if ($this->modelInfo['extend'] > 1) {
|
||||||
$map['model_id'] = $this->modelInfo['id'];
|
$map['model_id'] = $this->modelInfo['id'];
|
||||||
}else{
|
} else {
|
||||||
$model_id[] = $this->modelInfo['id'];
|
$model_id[] = $this->modelInfo['id'];
|
||||||
$model_id[] = 1;
|
$model_id[] = 1;
|
||||||
$map['model_id'] = array('IN',$model_id);
|
$map['model_id'] = array('IN', $model_id);
|
||||||
}
|
}
|
||||||
if (ACTION_NAME == 'add') {
|
if (ACTION_NAME == 'add') {
|
||||||
$map['is_show'] = array('in',array('1','2'));
|
$map['is_show'] = array('in', array('1', '2'));
|
||||||
}elseif(ACTION_NAME == 'edit'){
|
} elseif (ACTION_NAME == 'edit') {
|
||||||
$map['is_show'] = array('in',array('1','3'));
|
$map['is_show'] = array('in', array('1', '3'));
|
||||||
}
|
}
|
||||||
|
|
||||||
//获得数组的第一条数组
|
//获得数组的第一条数组
|
||||||
$first_key = array_keys($field_group);
|
$first_key = array_keys($field_group);
|
||||||
$fields = model('Attribute')->getFieldlist($map);
|
$fields = model('Attribute')->getFieldlist($map);
|
||||||
if (!empty($field_sort)) {
|
if (!empty($field_sort)) {
|
||||||
foreach ($field_sort as $key => $value) {
|
foreach ($field_sort as $key => $value) {
|
||||||
foreach ($value as $index) {
|
foreach ($value as $index) {
|
||||||
@@ -168,8 +168,8 @@ class Content extends User{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//未进行排序的放入第一组中
|
//未进行排序的放入第一组中
|
||||||
$fields[] = array('name'=>'model_id','type'=>'hidden'); //加入模型ID值
|
$fields[] = array('name' => 'model_id', 'type' => 'hidden'); //加入模型ID值
|
||||||
$fields[] = array('name'=>'id','type'=>'hidden'); //加入模型ID值
|
$fields[] = array('name' => 'id', 'type' => 'hidden'); //加入模型ID值
|
||||||
foreach ($fields as $key => $value) {
|
foreach ($fields as $key => $value) {
|
||||||
$groupfield[$first_key[0]][] = $value;
|
$groupfield[$first_key[0]][] = $value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
namespace app\user\controller;
|
namespace app\user\controller;
|
||||||
use app\common\controller\User;
|
use app\common\controller\User;
|
||||||
|
|
||||||
class Index extends User{
|
class Index extends User {
|
||||||
|
|
||||||
public function index(){
|
public function index() {
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ if (!function_exists('input')) {
|
|||||||
* @param string $filter 过滤方法
|
* @param string $filter 过滤方法
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function input($key, $default = null, $filter = null)
|
function input($key = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
if (0 === strpos($key, '?')) {
|
if (0 === strpos($key, '?')) {
|
||||||
$key = substr($key, 1);
|
$key = substr($key, 1);
|
||||||
@@ -124,7 +124,7 @@ if (!function_exists('input')) {
|
|||||||
if ($pos = strpos($key, '.')) {
|
if ($pos = strpos($key, '.')) {
|
||||||
// 指定参数来源
|
// 指定参数来源
|
||||||
$method = substr($key, 0, $pos);
|
$method = substr($key, 0, $pos);
|
||||||
if (in_array($method, ['get', 'post', 'put', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {
|
if (in_array($method, ['get', 'post', 'put', 'patch', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {
|
||||||
$key = substr($key, $pos + 1);
|
$key = substr($key, $pos + 1);
|
||||||
} else {
|
} else {
|
||||||
$method = 'param';
|
$method = 'param';
|
||||||
@@ -191,7 +191,7 @@ if (!function_exists('db')) {
|
|||||||
*/
|
*/
|
||||||
function db($name = '', $config = [])
|
function db($name = '', $config = [])
|
||||||
{
|
{
|
||||||
return Db::connect($config)->name($name);
|
return Db::connect($config, true)->name($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,12 +421,13 @@ if (!function_exists('view')) {
|
|||||||
* 渲染模板输出
|
* 渲染模板输出
|
||||||
* @param string $template 模板文件
|
* @param string $template 模板文件
|
||||||
* @param array $vars 模板变量
|
* @param array $vars 模板变量
|
||||||
|
* @param array $replace 模板替换
|
||||||
* @param integer $code 状态码
|
* @param integer $code 状态码
|
||||||
* @return \think\response\View
|
* @return \think\response\View
|
||||||
*/
|
*/
|
||||||
function view($template = '', $vars = [], $code = 200)
|
function view($template = '', $vars = [], $replace = [], $code = 200)
|
||||||
{
|
{
|
||||||
return Response::create($template, 'view', $code)->vars($vars);
|
return Response::create($template, 'view', $code)->replace($replace)->assign($vars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -337,9 +337,9 @@ class App
|
|||||||
} catch (\ReflectionException $e) {
|
} catch (\ReflectionException $e) {
|
||||||
// 操作不存在
|
// 操作不存在
|
||||||
if (method_exists($instance, '_empty')) {
|
if (method_exists($instance, '_empty')) {
|
||||||
$method = new \ReflectionMethod($instance, '_empty');
|
$reflect = new \ReflectionMethod($instance, '_empty');
|
||||||
$data = $method->invokeArgs($instance, [$action, '']);
|
$data = $reflect->invokeArgs($instance, [$action]);
|
||||||
self::$debug && Log::record('[ RUN ] ' . $method->__toString(), 'info');
|
self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info');
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
|
throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,11 +195,8 @@ class File extends SplFileObject
|
|||||||
{
|
{
|
||||||
$extension = strtolower(pathinfo($this->getInfo('name'), PATHINFO_EXTENSION));
|
$extension = strtolower(pathinfo($this->getInfo('name'), PATHINFO_EXTENSION));
|
||||||
/* 对图像文件进行严格检测 */
|
/* 对图像文件进行严格检测 */
|
||||||
if (in_array($extension, array('gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf'))) {
|
if (in_array($extension, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf']) && !in_array(exif_imagetype($this->filename), [1, 2, 3, 4, 6])) {
|
||||||
$imginfo = getimagesize($this->filename);
|
return false;
|
||||||
if (empty($imginfo) || ('gif' == $extension && empty($imginfo['bits']))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -756,7 +756,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$value = null;
|
$value = null;
|
||||||
}
|
}
|
||||||
if (!in_array($field, $this->change)) {
|
if (!in_array($field, $this->change)) {
|
||||||
$this->setAttr($field, isset($this->data[$field]) ? $this->data[$field] : $value);
|
$this->setAttr($field, !is_null($value) ? $value : (isset($this->data[$field]) ? $this->data[$field] : $value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ class Request
|
|||||||
protected $request = [];
|
protected $request = [];
|
||||||
protected $route = [];
|
protected $route = [];
|
||||||
protected $put;
|
protected $put;
|
||||||
protected $delete;
|
|
||||||
protected $session = [];
|
protected $session = [];
|
||||||
protected $file = [];
|
protected $file = [];
|
||||||
protected $cookie = [];
|
protected $cookie = [];
|
||||||
@@ -490,6 +489,7 @@ class Request
|
|||||||
} elseif (!$this->method) {
|
} elseif (!$this->method) {
|
||||||
if (isset($_POST[Config::get('var_method')])) {
|
if (isset($_POST[Config::get('var_method')])) {
|
||||||
$this->method = strtoupper($_POST[Config::get('var_method')]);
|
$this->method = strtoupper($_POST[Config::get('var_method')]);
|
||||||
|
$this->{$this->method}($_POST);
|
||||||
} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
|
} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
|
||||||
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
|
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
|
||||||
} else {
|
} else {
|
||||||
@@ -612,10 +612,9 @@ class Request
|
|||||||
$vars = $this->post(false);
|
$vars = $this->post(false);
|
||||||
break;
|
break;
|
||||||
case 'PUT':
|
case 'PUT':
|
||||||
$vars = $this->put(false);
|
|
||||||
break;
|
|
||||||
case 'DELETE':
|
case 'DELETE':
|
||||||
$vars = $this->delete(false);
|
case 'PATCH':
|
||||||
|
$vars = $this->put(false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$vars = [];
|
$vars = [];
|
||||||
@@ -718,13 +717,20 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function delete($name = '', $default = null, $filter = null)
|
public function delete($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
if (is_array($name)) {
|
return $this->put($name, $default, $filter);
|
||||||
return $this->delete = is_null($this->delete) ? $name : array_merge($this->delete, $name);
|
}
|
||||||
}
|
|
||||||
if (is_null($this->delete)) {
|
/**
|
||||||
parse_str(file_get_contents('php://input'), $this->delete);
|
* 设置获取获取PATCH参数
|
||||||
}
|
* @access public
|
||||||
return $this->input($this->delete, $name, $default, $filter);
|
* @param string|array $name 变量名
|
||||||
|
* @param mixed $default 默认值
|
||||||
|
* @param string|array $filter 过滤方法
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function patch($name = '', $default = null, $filter = null)
|
||||||
|
{
|
||||||
|
return $this->put($name, $default, $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class Route
|
|||||||
'POST' => [],
|
'POST' => [],
|
||||||
'PUT' => [],
|
'PUT' => [],
|
||||||
'DELETE' => [],
|
'DELETE' => [],
|
||||||
|
'PATCH' => [],
|
||||||
'HEAD' => [],
|
'HEAD' => [],
|
||||||
'OPTIONS' => [],
|
'OPTIONS' => [],
|
||||||
'*' => [],
|
'*' => [],
|
||||||
@@ -59,7 +60,7 @@ class Route
|
|||||||
// 域名绑定
|
// 域名绑定
|
||||||
private static $bind = [];
|
private static $bind = [];
|
||||||
// 当前分组
|
// 当前分组
|
||||||
private static $group;
|
private static $group = '';
|
||||||
// 当前参数
|
// 当前参数
|
||||||
private static $option = [];
|
private static $option = [];
|
||||||
|
|
||||||
@@ -242,7 +243,7 @@ class Route
|
|||||||
self::$rules[$type][$rule] = ['rule' => $rule, 'route' => $route, 'var' => $vars, 'option' => $option, 'pattern' => $pattern];
|
self::$rules[$type][$rule] = ['rule' => $rule, 'route' => $route, 'var' => $vars, 'option' => $option, 'pattern' => $pattern];
|
||||||
if ('*' == $type) {
|
if ('*' == $type) {
|
||||||
// 注册路由快捷方式
|
// 注册路由快捷方式
|
||||||
foreach (['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS'] as $method) {
|
foreach (['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'] as $method) {
|
||||||
self::$rules[$method][$rule] = true;
|
self::$rules[$method][$rule] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,7 +258,11 @@ class Route
|
|||||||
*/
|
*/
|
||||||
public static function setGroup($name)
|
public static function setGroup($name)
|
||||||
{
|
{
|
||||||
self::$group = $name;
|
if (self::$group) {
|
||||||
|
self::$group = self::$group . '/' . ltrim($name, '/');
|
||||||
|
} else {
|
||||||
|
self::$group = $name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -291,9 +296,11 @@ class Route
|
|||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
// 分组
|
// 分组
|
||||||
if ($routes instanceof \Closure) {
|
if ($routes instanceof \Closure) {
|
||||||
|
$curentGroup = self::$group;
|
||||||
self::setGroup($name);
|
self::setGroup($name);
|
||||||
call_user_func_array($routes, []);
|
call_user_func_array($routes, []);
|
||||||
self::setGroup(null);
|
self::$group = $curentGroup;
|
||||||
|
|
||||||
self::$rules[$type][$name]['route'] = '';
|
self::$rules[$type][$name]['route'] = '';
|
||||||
self::$rules[$type][$name]['var'] = self::parseVar($name);
|
self::$rules[$type][$name]['var'] = self::parseVar($name);
|
||||||
self::$rules[$type][$name]['option'] = $option;
|
self::$rules[$type][$name]['option'] = $option;
|
||||||
@@ -317,7 +324,7 @@ class Route
|
|||||||
self::$rules[$type][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern];
|
self::$rules[$type][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern];
|
||||||
}
|
}
|
||||||
if ('*' == $type) {
|
if ('*' == $type) {
|
||||||
foreach (['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS'] as $method) {
|
foreach (['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'] as $method) {
|
||||||
if (!isset(self::$rules[$method][$name])) {
|
if (!isset(self::$rules[$method][$name])) {
|
||||||
self::$rules[$method][$name] = true;
|
self::$rules[$method][$name] = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -408,6 +415,20 @@ class Route
|
|||||||
self::rule($rule, $route, 'DELETE', $option, $pattern);
|
self::rule($rule, $route, 'DELETE', $option, $pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册PATCH路由
|
||||||
|
* @access public
|
||||||
|
* @param string $rule 路由规则
|
||||||
|
* @param string $route 路由地址
|
||||||
|
* @param array $option 路由参数
|
||||||
|
* @param array $pattern 变量规则
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function patch($rule, $route = '', $option = [], $pattern = [])
|
||||||
|
{
|
||||||
|
self::rule($rule, $route, 'PATCH', $option, $pattern);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册资源路由
|
* 注册资源路由
|
||||||
* @access public
|
* @access public
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ use think\Route;
|
|||||||
|
|
||||||
class Url
|
class Url
|
||||||
{
|
{
|
||||||
// 生成URL地址的root
|
|
||||||
protected static $root;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL生成 支持路由反射
|
* URL生成 支持路由反射
|
||||||
* @param string $url URL表达式,
|
* @param string $url URL表达式,
|
||||||
@@ -116,7 +113,7 @@ class Url
|
|||||||
// 检测域名
|
// 检测域名
|
||||||
$domain = self::parseDomain($url, $domain);
|
$domain = self::parseDomain($url, $domain);
|
||||||
// URL组装
|
// URL组装
|
||||||
$url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/');
|
$url = $domain . Request::instance()->root() . '/' . ltrim($url, '/');
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,11 +316,4 @@ class Url
|
|||||||
{
|
{
|
||||||
Cache::rm('think_route_map');
|
Cache::rm('think_route_map');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 指定当前生成URL地址的root
|
|
||||||
public static function root($root)
|
|
||||||
{
|
|
||||||
self::$root = $root;
|
|
||||||
Request::instance()->root($root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -68,6 +68,7 @@ class Validate
|
|||||||
'allowIp' => '不允许的IP访问',
|
'allowIp' => '不允许的IP访问',
|
||||||
'denyIp' => '禁止的IP访问',
|
'denyIp' => '禁止的IP访问',
|
||||||
'confirm' => ':attribute和字段 :rule 不一致',
|
'confirm' => ':attribute和字段 :rule 不一致',
|
||||||
|
'different' => ':attribute和字段 :rule 不能相同',
|
||||||
'egt' => ':attribute必须大于等于 :rule',
|
'egt' => ':attribute必须大于等于 :rule',
|
||||||
'gt' => ':attribute必须大于 :rule',
|
'gt' => ':attribute必须大于 :rule',
|
||||||
'elt' => ':attribute必须小于等于 :rule',
|
'elt' => ':attribute必须小于等于 :rule',
|
||||||
@@ -400,6 +401,19 @@ class Validate
|
|||||||
return $this->getDataValue($data, $rule) == $value;
|
return $this->getDataValue($data, $rule) == $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证是否和某个字段的值是否不同
|
||||||
|
* @access protected
|
||||||
|
* @param mixed $value 字段值
|
||||||
|
* @param mixed $rule 验证规则
|
||||||
|
* @param array $data 数据
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function different($value, $rule, $data)
|
||||||
|
{
|
||||||
|
return $this->getDataValue($data, $rule) != $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证是否大于等于某个值
|
* 验证是否大于等于某个值
|
||||||
* @access protected
|
* @access protected
|
||||||
|
|||||||
@@ -11,8 +11,9 @@
|
|||||||
|
|
||||||
namespace think\controller;
|
namespace think\controller;
|
||||||
|
|
||||||
use think\Response;
|
use think\App;
|
||||||
use think\Request;
|
use think\Request;
|
||||||
|
use think\Response;
|
||||||
|
|
||||||
abstract class Rest
|
abstract class Rest
|
||||||
{
|
{
|
||||||
@@ -38,7 +39,7 @@ abstract class Rest
|
|||||||
{
|
{
|
||||||
// 资源类型检测
|
// 资源类型检测
|
||||||
$request = Request::instance();
|
$request = Request::instance();
|
||||||
$ext = $request->ext();
|
$ext = $request->ext();
|
||||||
if ('' == $ext) {
|
if ('' == $ext) {
|
||||||
// 自动检测资源类型
|
// 自动检测资源类型
|
||||||
$this->type = $request->type();
|
$this->type = $request->type();
|
||||||
@@ -61,11 +62,10 @@ abstract class Rest
|
|||||||
* REST 调用
|
* REST 调用
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $method 方法名
|
* @param string $method 方法名
|
||||||
* @param array $args 参数
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function _empty($method, $args)
|
public function _empty($method)
|
||||||
{
|
{
|
||||||
if (method_exists($this, $method . '_' . $this->method . '_' . $this->type)) {
|
if (method_exists($this, $method . '_' . $this->method . '_' . $this->type)) {
|
||||||
// RESTFul方法支持
|
// RESTFul方法支持
|
||||||
@@ -76,7 +76,7 @@ abstract class Rest
|
|||||||
$fun = $method . '_' . $this->method;
|
$fun = $method . '_' . $this->method;
|
||||||
}
|
}
|
||||||
if (isset($fun)) {
|
if (isset($fun)) {
|
||||||
return $this->$fun();
|
return App::invokeMethod([$this, $fun]);
|
||||||
} else {
|
} else {
|
||||||
// 抛出异常
|
// 抛出异常
|
||||||
throw new \Exception('error action :' . $method);
|
throw new \Exception('error action :' . $method);
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ class Query
|
|||||||
protected function builder()
|
protected function builder()
|
||||||
{
|
{
|
||||||
static $builder = [];
|
static $builder = [];
|
||||||
$driver = $this->driver;
|
$driver = $this->driver;
|
||||||
if (!isset($builder[$driver])) {
|
if (!isset($builder[$driver])) {
|
||||||
$class = '\\think\\db\\builder\\' . ucfirst($driver);
|
$class = '\\think\\db\\builder\\' . ucfirst($driver);
|
||||||
$builder[$driver] = new $class($this->connection);
|
$builder[$driver] = new $class($this->connection);
|
||||||
@@ -660,7 +660,7 @@ class Query
|
|||||||
}
|
}
|
||||||
if (count($join)) {
|
if (count($join)) {
|
||||||
// 有设置第二个元素则把第二元素作为表前缀
|
// 有设置第二个元素则把第二元素作为表前缀
|
||||||
$table = (string)current($join) . $table;
|
$table = (string) current($join) . $table;
|
||||||
} elseif (false === strpos($table, '.')) {
|
} elseif (false === strpos($table, '.')) {
|
||||||
// 加上默认的表前缀
|
// 加上默认的表前缀
|
||||||
$table = $prefix . $table;
|
$table = $prefix . $table;
|
||||||
@@ -975,7 +975,7 @@ class Query
|
|||||||
|
|
||||||
/** @var Paginator $class */
|
/** @var Paginator $class */
|
||||||
$class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\' . ucwords($config['type']);
|
$class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\' . ucwords($config['type']);
|
||||||
$page = isset($config['page']) ? (int)$config['page'] : call_user_func([
|
$page = isset($config['page']) ? (int) $config['page'] : call_user_func([
|
||||||
$class,
|
$class,
|
||||||
'getCurrentPage',
|
'getCurrentPage',
|
||||||
], $config['var_page']);
|
], $config['var_page']);
|
||||||
@@ -983,7 +983,7 @@ class Query
|
|||||||
$page = $page < 1 ? 1 : $page;
|
$page = $page < 1 ? 1 : $page;
|
||||||
|
|
||||||
$config['path'] = isset($config['path']) ? $config['path'] : call_user_func([$class, 'getCurrentPath']);
|
$config['path'] = isset($config['path']) ? $config['path'] : call_user_func([$class, 'getCurrentPath']);
|
||||||
|
|
||||||
if (!$simple) {
|
if (!$simple) {
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
$total = $this->count();
|
$total = $this->count();
|
||||||
@@ -1326,7 +1326,7 @@ class Query
|
|||||||
if (!isset($this->info[$guid])) {
|
if (!isset($this->info[$guid])) {
|
||||||
$info = $this->connection->getFields($tableName);
|
$info = $this->connection->getFields($tableName);
|
||||||
$fields = array_keys($info);
|
$fields = array_keys($info);
|
||||||
$bind = $type = [];
|
$bind = $type = [];
|
||||||
foreach ($info as $key => $val) {
|
foreach ($info as $key => $val) {
|
||||||
// 记录字段类型
|
// 记录字段类型
|
||||||
$type[$key] = $val['type'];
|
$type[$key] = $val['type'];
|
||||||
@@ -1444,7 +1444,7 @@ class Query
|
|||||||
$relation = $key;
|
$relation = $key;
|
||||||
$with[$key] = $key;
|
$with[$key] = $key;
|
||||||
} elseif (is_string($relation) && strpos($relation, '.')) {
|
} elseif (is_string($relation) && strpos($relation, '.')) {
|
||||||
$with[$key] = $relation;
|
$with[$key] = $relation;
|
||||||
list($relation, $subRelation) = explode('.', $relation, 2);
|
list($relation, $subRelation) = explode('.', $relation, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1479,7 +1479,7 @@ class Query
|
|||||||
|
|
||||||
if ($closure) {
|
if ($closure) {
|
||||||
// 执行闭包查询
|
// 执行闭包查询
|
||||||
call_user_func_array($closure, [& $this]);
|
call_user_func_array($closure, [ & $this]);
|
||||||
//指定获取关联的字段
|
//指定获取关联的字段
|
||||||
//需要在 回调中 调方法 withField 方法,如
|
//需要在 回调中 调方法 withField 方法,如
|
||||||
// $query->where(['id'=>1])->withField('id,name');
|
// $query->where(['id'=>1])->withField('id,name');
|
||||||
@@ -1599,13 +1599,15 @@ class Query
|
|||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
// 生成SQL语句
|
// 生成SQL语句
|
||||||
$sql = $this->builder()->insert($data, $options, $replace);
|
$sql = $this->builder()->insert($data, $options, $replace);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
}
|
}
|
||||||
$sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
|
$sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return $this->execute($sql, $this->getBind(), $getLastInsID, $sequence);
|
return $this->execute($sql, $bind, $getLastInsID, $sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1636,12 +1638,14 @@ class Query
|
|||||||
}
|
}
|
||||||
// 生成SQL语句
|
// 生成SQL语句
|
||||||
$sql = $this->builder()->insertAll($dataSet, $options);
|
$sql = $this->builder()->insertAll($dataSet, $options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
} else {
|
} else {
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return $this->execute($sql, $this->getBind());
|
return $this->execute($sql, $bind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1660,12 +1664,14 @@ class Query
|
|||||||
// 生成SQL语句
|
// 生成SQL语句
|
||||||
$table = $this->parseSqlTable($table);
|
$table = $this->parseSqlTable($table);
|
||||||
$sql = $this->builder()->selectInsert($fields, $table, $options);
|
$sql = $this->builder()->selectInsert($fields, $table, $options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
} else {
|
} else {
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return $this->execute($sql, $this->getBind());
|
return $this->execute($sql, $bind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1708,9 +1714,11 @@ class Query
|
|||||||
}
|
}
|
||||||
// 生成UPDATE SQL语句
|
// 生成UPDATE SQL语句
|
||||||
$sql = $this->builder()->update($data, $options);
|
$sql = $this->builder()->update($data, $options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
} else {
|
} else {
|
||||||
// 检测缓存
|
// 检测缓存
|
||||||
if (isset($key) && Cache::get($key)) {
|
if (isset($key) && Cache::get($key)) {
|
||||||
@@ -1718,7 +1726,7 @@ class Query
|
|||||||
Cache::rm($key);
|
Cache::rm($key);
|
||||||
}
|
}
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return '' == $sql ? 0 : $this->execute($sql, $this->getBind());
|
return '' == $sql ? 0 : $this->execute($sql, $bind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1736,7 +1744,7 @@ class Query
|
|||||||
if ($data instanceof Query) {
|
if ($data instanceof Query) {
|
||||||
return $data->select();
|
return $data->select();
|
||||||
} elseif ($data instanceof \Closure) {
|
} elseif ($data instanceof \Closure) {
|
||||||
call_user_func_array($data, [& $this]);
|
call_user_func_array($data, [ & $this]);
|
||||||
$data = null;
|
$data = null;
|
||||||
}
|
}
|
||||||
// 分析查询表达式
|
// 分析查询表达式
|
||||||
@@ -1760,12 +1768,14 @@ class Query
|
|||||||
if (!$resultSet) {
|
if (!$resultSet) {
|
||||||
// 生成查询SQL
|
// 生成查询SQL
|
||||||
$sql = $this->builder()->select($options);
|
$sql = $this->builder()->select($options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
}
|
}
|
||||||
// 执行查询操作
|
// 执行查询操作
|
||||||
$resultSet = $this->query($sql, $this->getBind(), $options['master'], $options['fetch_class']);
|
$resultSet = $this->query($sql, $bind, $options['master'], $options['fetch_class']);
|
||||||
|
|
||||||
if ($resultSet instanceof \PDOStatement) {
|
if ($resultSet instanceof \PDOStatement) {
|
||||||
// 返回PDOStatement对象
|
// 返回PDOStatement对象
|
||||||
@@ -1819,7 +1829,7 @@ class Query
|
|||||||
if ($data instanceof Query) {
|
if ($data instanceof Query) {
|
||||||
return $data->find();
|
return $data->find();
|
||||||
} elseif ($data instanceof \Closure) {
|
} elseif ($data instanceof \Closure) {
|
||||||
call_user_func_array($data, [& $this]);
|
call_user_func_array($data, [ & $this]);
|
||||||
$data = null;
|
$data = null;
|
||||||
}
|
}
|
||||||
// 分析查询表达式
|
// 分析查询表达式
|
||||||
@@ -1845,12 +1855,14 @@ class Query
|
|||||||
if (!$result) {
|
if (!$result) {
|
||||||
// 生成查询SQL
|
// 生成查询SQL
|
||||||
$sql = $this->builder()->select($options);
|
$sql = $this->builder()->select($options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
}
|
}
|
||||||
// 执行查询
|
// 执行查询
|
||||||
$result = $this->query($sql, $this->getBind(), $options['master'], $options['fetch_class']);
|
$result = $this->query($sql, $bind, $options['master'], $options['fetch_class']);
|
||||||
|
|
||||||
if ($result instanceof \PDOStatement) {
|
if ($result instanceof \PDOStatement) {
|
||||||
// 返回PDOStatement对象
|
// 返回PDOStatement对象
|
||||||
@@ -2015,10 +2027,11 @@ class Query
|
|||||||
}
|
}
|
||||||
// 生成删除SQL语句
|
// 生成删除SQL语句
|
||||||
$sql = $this->builder()->delete($options);
|
$sql = $this->builder()->delete($options);
|
||||||
|
// 获取参数绑定
|
||||||
|
$bind = $this->getBind();
|
||||||
if ($options['fetch_sql']) {
|
if ($options['fetch_sql']) {
|
||||||
// 获取实际执行的SQL语句
|
// 获取实际执行的SQL语句
|
||||||
return $this->connection->getRealSql($sql, $this->bind);
|
return $this->connection->getRealSql($sql, $bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测缓存
|
// 检测缓存
|
||||||
@@ -2027,7 +2040,7 @@ class Query
|
|||||||
Cache::rm($key);
|
Cache::rm($key);
|
||||||
}
|
}
|
||||||
// 执行操作
|
// 执行操作
|
||||||
return $this->execute($sql, $this->getBind());
|
return $this->execute($sql, $bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2112,10 +2125,10 @@ class Query
|
|||||||
if (isset($options['page'])) {
|
if (isset($options['page'])) {
|
||||||
// 根据页数计算limit
|
// 根据页数计算limit
|
||||||
list($page, $listRows) = $options['page'];
|
list($page, $listRows) = $options['page'];
|
||||||
$page = $page > 0 ? $page : 1;
|
$page = $page > 0 ? $page : 1;
|
||||||
$listRows = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20);
|
$listRows = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20);
|
||||||
$offset = $listRows * ($page - 1);
|
$offset = $listRows * ($page - 1);
|
||||||
$options['limit'] = $offset . ',' . $listRows;
|
$options['limit'] = $offset . ',' . $listRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->options = [];
|
$this->options = [];
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ class Handle
|
|||||||
'message' => $this->getMessage($exception),
|
'message' => $this->getMessage($exception),
|
||||||
'code' => $this->getCode($exception),
|
'code' => $this->getCode($exception),
|
||||||
];
|
];
|
||||||
$log = "[{$data['code']}]{$data['message']}[{$data['file']}:{$data['line']}]";
|
$log = "[{$data['code']}]{$data['message']}[{$data['file']}:{$data['line']}]";
|
||||||
} else {
|
} else {
|
||||||
$data = [
|
$data = [
|
||||||
'code' => $this->getCode($exception),
|
'code' => $this->getCode($exception),
|
||||||
'message' => $this->getMessage($exception),
|
'message' => $this->getMessage($exception),
|
||||||
];
|
];
|
||||||
$log = "[{$data['code']}]{$data['message']}";
|
$log = "[{$data['code']}]{$data['message']}";
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::record($log, 'error');
|
Log::record($log, 'error');
|
||||||
@@ -103,7 +103,7 @@ class Handle
|
|||||||
$status = $e->getStatusCode();
|
$status = $e->getStatusCode();
|
||||||
$template = Config::get('http_exception_template');
|
$template = Config::get('http_exception_template');
|
||||||
if (!App::$debug && !empty($template[$status])) {
|
if (!App::$debug && !empty($template[$status])) {
|
||||||
return Response::create($template[$status], 'view')->vars(['e' => $e]);
|
return Response::create($template[$status], 'view', $status)->assign(['e' => $e]);
|
||||||
} else {
|
} else {
|
||||||
return $this->convertExceptionToResponse($e);
|
return $this->convertExceptionToResponse($e);
|
||||||
}
|
}
|
||||||
@@ -155,9 +155,9 @@ class Handle
|
|||||||
while (ob_get_level() > 1) {
|
while (ob_get_level() > 1) {
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['echo'] = ob_get_clean();
|
$data['echo'] = ob_get_clean();
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
extract($data);
|
extract($data);
|
||||||
include Config::get('exception_tmpl');
|
include Config::get('exception_tmpl');
|
||||||
|
|||||||
@@ -36,18 +36,6 @@ class View extends Response
|
|||||||
->fetch($data, $this->vars, $this->replace);
|
->fetch($data, $this->vars, $this->replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 视图变量赋值
|
|
||||||
* @access public
|
|
||||||
* @param array $vars 模板变量
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function vars($vars = [])
|
|
||||||
{
|
|
||||||
$this->vars = $vars;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取视图变量
|
* 获取视图变量
|
||||||
* @access public
|
* @access public
|
||||||
@@ -56,11 +44,11 @@ class View extends Response
|
|||||||
*/
|
*/
|
||||||
public function getVars($name = null)
|
public function getVars($name = null)
|
||||||
{
|
{
|
||||||
if(is_null($name)){
|
if (is_null($name)) {
|
||||||
return $this->vars;
|
return $this->vars;
|
||||||
}else{
|
} else {
|
||||||
return isset($this->vars[$name]) ? $this->vars[$name] : null;
|
return isset($this->vars[$name]) ? $this->vars[$name] : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user