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