迅睿CMS框架是一款PHP8高性能·簡單易用的CMS開源開發(fā)框架,基于MIT開源許可協(xié)議發(fā)布,免費且不限制商業(yè)使用,是免費開源的產(chǎn)品,以萬端互聯(lián)為設計理念,支持的微信公眾號、小程序、APP客戶端、移動端網(wǎng)站、PC網(wǎng)站等多終端式管理系統(tǒng)。
聯(lián)系官方銷售客服
1835022288
028-61286886
PHP程序里面
插件之定義字段復選框多選保存報錯
這個要怎么處理
PHP文件:URL地址:
插件名稱:
什么是插件之定義字段復選框多選保存報錯
自己做的一個表單插件 自定義字段復選框多選保存報錯
回復迅睿框架創(chuàng)始人
點提交按鈕會彈出一些字母,看看內(nèi)容
需要格式化一下
加了還是報錯 選擇一個不會報錯 但是讀取不出來
回復迅??蚣軇?chuàng)始人
看下錯微軟日志詳情
日志的重要性,不看日志找不出問題所在的
這個是哪里的問題
回復@歡喜哥
很明顯了,這個字段的問題
這個怎么處理
回復@易學習
把全部控制器的代碼發(fā)來看看,部分代碼很難看出問題
回復@夢幻
加一個$data['xxxx'] = dr_array2string($data['xxxx']);
save里面
這個可以改成只要是復選框就格式處理不指定單個字段名稱
正解,使用了save方法,format_data就沒效果了
這個怎么用
不要截圖,全部發(fā)代碼,我改改應該就可以了,很明顯是沒有格式化數(shù)組
<?php namespace Phpcmf\Controllers\Admin;
class Home extends \Phpcmf\Table
{
public function __construct(...$params) {
parent::__construct(...$params);
\Phpcmf\Service::V()->assign('menu', \Phpcmf\Service::M('auth')->_admin_menu(
[
'表單管理' => [APP_DIR.'/home/index', 'fa fa-area-chart'],
]
));
// 表單顯示名稱
$this->name = dr_lang('表單');
// 模板前綴(避免混淆)
$this->tpl_prefix = 'config_';
// 用于表儲存的字段,后臺可修改的表字段
$this->field = \Phpcmf\Service::L('cache')->get('xcrm'.'-field');
$field = array ();
// 初始化數(shù)據(jù)表
$this->_init([
'table' => 'xcrm_customer', // (不帶前綴的)表名字
'fields' => $field,
'field' => $this->field, // 可查詢的字段
'order_by' => 'id desc', // 列表排序,默認的排序方式
'date_field' => 'inputtime', // 按時間段搜索字段,沒有時間字段留空
]);
// 把公共變量傳入模板
\Phpcmf\Service::V()->assign([
// 搜索字段
'fields' =>$field,
'field' => $this->field,
'is_time_where' => $this->init['date_field'],
// 后臺的菜單
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
$this->name => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-code'],
'添加' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/add', 'fa fa-plus'],
'修改' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
]),
}
// 查看列表
public function index() {
list($tpl, $data) = $this->_List();
\Phpcmf\Service::V()->display('config_list.html');
// 添加內(nèi)容
public function add() {
list($tpl ,$data) = $this->_Post(0);
\Phpcmf\Service::V()->display('config_add.html');
// 修改內(nèi)容
public function edit() {
$id = intval(\Phpcmf\Service::L('Input')->get('id'));
list($tpl, $data) = $this->_Post($id);
if (!$data) {
$this->_admin_msg(0, dr_lang('內(nèi)容不存在'));
\Phpcmf\Service::V()->display($tpl);
//分配
public function me_edit() {
$in = $ids =[];
$ids = \Phpcmf\Service::L('input')->get_post_ids();
foreach ($ids as $i) {
$i && $in[] = intval($i);
if($ids){
$uid = \Phpcmf\Service::L('input')->post('uid');
if($uid != 0){
$data = array(
'uid' => $uid,
);
\Phpcmf\Service::M()->db->table('xcrm_customer')->whereIn('id', $in)->update($data);
$this->_json(1, dr_lang('操作成功'));
}else{
$this->_json(0, dr_lang('沒選擇用戶'));
$this->_json(0, dr_lang('沒選擇數(shù)據(jù)'));
// 刪除內(nèi)容
public function del() {
$this->_Del(
\Phpcmf\Service::L('Input')->get_post_ids(),
function($rows) {
// 刪除前的驗證
return dr_return_data(1, 'ok', $rows);
},
// 刪除后的處理
foreach($rows as $t){
$cid = (int)$t['id'];
\Phpcmf\Service::M()->table('xcrm_record')->where('cid', $cid)->delete();
return dr_return_data(1, 'ok');
\Phpcmf\Service::M()->dbprefix($this->init['table'])
/**
* 獲取內(nèi)容
* $id 內(nèi)容id,新增為0
* */
protected function _Data($id = 0) {
$row = parent::_Data($id);
// 這里可以對內(nèi)容進行格式化顯示操處理
return $row;
// 格式化保存數(shù)據(jù)
protected function _Format_Data($id, $data, $old) {
if (!$id) {
// 當提交新數(shù)據(jù)時,把當前時間插入進去
$data[1]['inputtime'] = SYS_TIME;
//$data[1]['dingjin'] = dr_array2string($data[1]['dingjin']);
//print_r($data);exit;
return $data;
// 保存內(nèi)容
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
$data = \Phpcmf\Service::L('input')->post('data');
return parent::_Save($id, $data, $old, function($id, $data, $old){
// 驗證數(shù)據(jù)
$data['dingjin'] = dr_array2string($data['dingjin']);
// 保存之前執(zhí)行的函數(shù),并返回新的數(shù)據(jù)
$data['inputtime'] = SYS_TIME;
if ($data['updatetime']) {
$data['updatetime'] = strtotime($data['updatetime']);
return dr_return_data(1, null, $data);
}, function ($id, $data, $old) {
// 保存之后執(zhí)行的動作
if($data['follow']){
$datas = array(
'oid' => $data['oid'],
'cid' => $id,
'content' => $data['follow'],
'inputtime' => SYS_TIME,
\Phpcmf\Service::M()->db->table('xcrm_record')->insert($datas);
});
// 后臺批量保存排序值
public function order_edit() {
$this->_Display_Order(
intval(\Phpcmf\Service::L('Input')->get('id')),
intval(\Phpcmf\Service::L('Input')->get('value')),
function ($r) {
\Phpcmf\Service::M('xcrm', APP_DIR)->cache();
<?php namespace Phpcmf\Controllers\Admin; class Home extends \Phpcmf\Table { public function __construct(...$params) { parent::__construct(...$params); \Phpcmf\Service::V()->assign('menu', \Phpcmf\Service::M('auth')->_admin_menu( [ '表單管理' => [APP_DIR.'/home/index', 'fa fa-area-chart'], ] )); // 表單顯示名稱 $this->name = dr_lang('表單'); // 模板前綴(避免混淆) $this->tpl_prefix = 'config_'; // 用于表儲存的字段,后臺可修改的表字段 $this->field = \Phpcmf\Service::L('cache')->get('xcrm'.'-field'); $field = array (); // 初始化數(shù)據(jù)表 $this->_init([ 'table' => 'xcrm_customer', // (不帶前綴的)表名字 'fields' => $field, 'field' => $this->field, // 可查詢的字段 'order_by' => 'id desc', // 列表排序,默認的排序方式 'date_field' => 'inputtime', // 按時間段搜索字段,沒有時間字段留空 ]); // 把公共變量傳入模板 \Phpcmf\Service::V()->assign([ // 搜索字段 'fields' =>$field, 'field' => $this->field, 'is_time_where' => $this->init['date_field'], // 后臺的菜單 'menu' => \Phpcmf\Service::M('auth')->_admin_menu( [ $this->name => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-code'], '添加' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/add', 'fa fa-plus'], '修改' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'], ]), ]); } // 查看列表 public function index() { list($tpl, $data) = $this->_List(); \Phpcmf\Service::V()->display('config_list.html'); } // 添加內(nèi)容 public function add() { list($tpl ,$data) = $this->_Post(0); \Phpcmf\Service::V()->display('config_add.html'); } // 修改內(nèi)容 public function edit() { $id = intval(\Phpcmf\Service::L('Input')->get('id')); list($tpl, $data) = $this->_Post($id); if (!$data) { $this->_admin_msg(0, dr_lang('內(nèi)容不存在')); } \Phpcmf\Service::V()->display($tpl); } //分配 public function me_edit() { $in = $ids =[]; $ids = \Phpcmf\Service::L('input')->get_post_ids(); foreach ($ids as $i) { $i && $in[] = intval($i); } if($ids){ $uid = \Phpcmf\Service::L('input')->post('uid'); if($uid != 0){ $data = array( 'uid' => $uid, ); \Phpcmf\Service::M()->db->table('xcrm_customer')->whereIn('id', $in)->update($data); $this->_json(1, dr_lang('操作成功')); }else{ $this->_json(0, dr_lang('沒選擇用戶')); } }else{ $this->_json(0, dr_lang('沒選擇數(shù)據(jù)')); } } // 刪除內(nèi)容 public function del() { $this->_Del( \Phpcmf\Service::L('Input')->get_post_ids(), function($rows) { // 刪除前的驗證 return dr_return_data(1, 'ok', $rows); }, function($rows) { // 刪除后的處理 foreach($rows as $t){ $cid = (int)$t['id']; \Phpcmf\Service::M()->table('xcrm_record')->where('cid', $cid)->delete(); } return dr_return_data(1, 'ok'); }, \Phpcmf\Service::M()->dbprefix($this->init['table']) ); } // 保存內(nèi)容 protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) { $data = \Phpcmf\Service::L('input')->post('data'); return parent::_Save($id, $data, $old, function($id, $data, $old){ // 驗證數(shù)據(jù) $data['dingjin'] = dr_array2string($data['dingjin']); // 保存之前執(zhí)行的函數(shù),并返回新的數(shù)據(jù) if (!$id) { // 當提交新數(shù)據(jù)時,把當前時間插入進去 $data['inputtime'] = SYS_TIME; } if ($data['updatetime']) { $data['updatetime'] = strtotime($data['updatetime']); } print_r($data);exit; return dr_return_data(1, null, $data); }, function ($id, $data, $old) { // 保存之后執(zhí)行的動作 if($data['follow']){ $datas = array( 'oid' => $data['oid'], 'cid' => $id, 'content' => $data['follow'], 'inputtime' => SYS_TIME, ); \Phpcmf\Service::M()->db->table('xcrm_record')->insert($datas); } }); } // 后臺批量保存排序值 public function order_edit() { $this->_Display_Order( intval(\Phpcmf\Service::L('Input')->get('id')), intval(\Phpcmf\Service::L('Input')->get('value')), function ($r) { \Phpcmf\Service::M('xcrm', APP_DIR)->cache(); } ); } }
新添加的復選框還是要添加了才可以
怎么才能只要是復選框都可以
可以加我QQ遠程,我做了無數(shù)次table類的控制器入庫了
你QQ好多
查詢下 是否是數(shù)組 is_array 如果是數(shù)組就dr_array2string 轉(zhuǎn)換一下
能給個樣本么
回復@九天網(wǎng)絡(JiuDay)
我也是很服了你。你另一個帖子 解決了。倒是留下你的解決方法和不行的原因。前人栽樹 后人好乘涼呀。 下次別人也遇到同樣需求 最快的能解決不是。
你這個我沒法給你樣本 你自己想吧。思路給你了
我那個就用的你發(fā)的方法 我最開始條件寫錯了
foreach ($data as $name => $value) { if (is_array($data[$name])) { $data[$name] = dr_array2string($data[$name]); } }
應該是這樣 你自己測試下
什么是插件之定義字段復選框多選保存報錯
自己做的一個表單插件 自定義字段復選框多選保存報錯
回復迅睿框架創(chuàng)始人
點提交按鈕會彈出一些字母,看看內(nèi)容
回復迅睿框架創(chuàng)始人
需要格式化一下
加了還是報錯 選擇一個不會報錯 但是讀取不出來
回復迅??蚣軇?chuàng)始人
看下錯微軟日志詳情
回復迅睿框架創(chuàng)始人
日志的重要性,不看日志找不出問題所在的
這個是哪里的問題
回復@歡喜哥
很明顯了,這個字段的問題
這個怎么處理
回復@易學習
把全部控制器的代碼發(fā)來看看,部分代碼很難看出問題
回復@夢幻
回復@易學習
加一個$data['xxxx'] = dr_array2string($data['xxxx']);
save里面
這個可以改成只要是復選框就格式處理不指定單個字段名稱
回復@易學習
正解,使用了save方法,format_data就沒效果了
回復@易學習
這個怎么用
回復迅??蚣軇?chuàng)始人
把全部控制器的代碼發(fā)來看看,部分代碼很難看出問題
回復@夢幻
不要截圖,全部發(fā)代碼,我改改應該就可以了,很明顯是沒有格式化數(shù)組
<?php namespace Phpcmf\Controllers\Admin;
class Home extends \Phpcmf\Table
{
public function __construct(...$params) {
parent::__construct(...$params);
\Phpcmf\Service::V()->assign('menu', \Phpcmf\Service::M('auth')->_admin_menu(
[
'表單管理' => [APP_DIR.'/home/index', 'fa fa-area-chart'],
]
));
// 表單顯示名稱
$this->name = dr_lang('表單');
// 模板前綴(避免混淆)
$this->tpl_prefix = 'config_';
// 用于表儲存的字段,后臺可修改的表字段
$this->field = \Phpcmf\Service::L('cache')->get('xcrm'.'-field');
$field = array ();
// 初始化數(shù)據(jù)表
$this->_init([
'table' => 'xcrm_customer', // (不帶前綴的)表名字
'fields' => $field,
'field' => $this->field, // 可查詢的字段
'order_by' => 'id desc', // 列表排序,默認的排序方式
'date_field' => 'inputtime', // 按時間段搜索字段,沒有時間字段留空
]);
// 把公共變量傳入模板
\Phpcmf\Service::V()->assign([
// 搜索字段
'fields' =>$field,
'field' => $this->field,
'is_time_where' => $this->init['date_field'],
// 后臺的菜單
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
[
$this->name => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-code'],
'添加' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/add', 'fa fa-plus'],
'修改' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
]),
]);
}
// 查看列表
public function index() {
list($tpl, $data) = $this->_List();
\Phpcmf\Service::V()->display('config_list.html');
}
// 添加內(nèi)容
public function add() {
list($tpl ,$data) = $this->_Post(0);
\Phpcmf\Service::V()->display('config_add.html');
}
// 修改內(nèi)容
public function edit() {
$id = intval(\Phpcmf\Service::L('Input')->get('id'));
list($tpl, $data) = $this->_Post($id);
if (!$data) {
$this->_admin_msg(0, dr_lang('內(nèi)容不存在'));
}
\Phpcmf\Service::V()->display($tpl);
}
//分配
public function me_edit() {
$in = $ids =[];
$ids = \Phpcmf\Service::L('input')->get_post_ids();
foreach ($ids as $i) {
$i && $in[] = intval($i);
}
if($ids){
$uid = \Phpcmf\Service::L('input')->post('uid');
if($uid != 0){
$data = array(
'uid' => $uid,
);
\Phpcmf\Service::M()->db->table('xcrm_customer')->whereIn('id', $in)->update($data);
$this->_json(1, dr_lang('操作成功'));
}else{
$this->_json(0, dr_lang('沒選擇用戶'));
}
}else{
$this->_json(0, dr_lang('沒選擇數(shù)據(jù)'));
}
}
// 刪除內(nèi)容
public function del() {
$this->_Del(
\Phpcmf\Service::L('Input')->get_post_ids(),
function($rows) {
// 刪除前的驗證
return dr_return_data(1, 'ok', $rows);
},
function($rows) {
// 刪除后的處理
foreach($rows as $t){
$cid = (int)$t['id'];
\Phpcmf\Service::M()->table('xcrm_record')->where('cid', $cid)->delete();
}
return dr_return_data(1, 'ok');
},
\Phpcmf\Service::M()->dbprefix($this->init['table'])
);
}
/**
* 獲取內(nèi)容
* $id 內(nèi)容id,新增為0
* */
protected function _Data($id = 0) {
$row = parent::_Data($id);
// 這里可以對內(nèi)容進行格式化顯示操處理
return $row;
}
// 格式化保存數(shù)據(jù)
protected function _Format_Data($id, $data, $old) {
if (!$id) {
// 當提交新數(shù)據(jù)時,把當前時間插入進去
$data[1]['inputtime'] = SYS_TIME;
}
//$data[1]['dingjin'] = dr_array2string($data[1]['dingjin']);
//print_r($data);exit;
return $data;
}
// 保存內(nèi)容
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
$data = \Phpcmf\Service::L('input')->post('data');
return parent::_Save($id, $data, $old, function($id, $data, $old){
// 驗證數(shù)據(jù)
$data['dingjin'] = dr_array2string($data['dingjin']);
// 保存之前執(zhí)行的函數(shù),并返回新的數(shù)據(jù)
if (!$id) {
// 當提交新數(shù)據(jù)時,把當前時間插入進去
$data['inputtime'] = SYS_TIME;
}
if ($data['updatetime']) {
$data['updatetime'] = strtotime($data['updatetime']);
}
return dr_return_data(1, null, $data);
}, function ($id, $data, $old) {
// 保存之后執(zhí)行的動作
if($data['follow']){
$datas = array(
'oid' => $data['oid'],
'cid' => $id,
'content' => $data['follow'],
'inputtime' => SYS_TIME,
);
\Phpcmf\Service::M()->db->table('xcrm_record')->insert($datas);
}
});
}
// 后臺批量保存排序值
public function order_edit() {
$this->_Display_Order(
intval(\Phpcmf\Service::L('Input')->get('id')),
intval(\Phpcmf\Service::L('Input')->get('value')),
function ($r) {
\Phpcmf\Service::M('xcrm', APP_DIR)->cache();
}
);
}
}
回復@易學習
新添加的復選框還是要添加了才可以
怎么才能只要是復選框都可以
回復@易學習
可以加我QQ遠程,我做了無數(shù)次table類的控制器入庫了
你QQ好多
回復@易學習
能給個樣本么
回復@九天網(wǎng)絡(JiuDay)
我也是很服了你。你另一個帖子 解決了。倒是留下你的解決方法和不行的原因。前人栽樹 后人好乘涼呀。 下次別人也遇到同樣需求 最快的能解決不是。
你這個我沒法給你樣本 你自己想吧。思路給你了
我那個就用的你發(fā)的方法 我最開始條件寫錯了
回復@九天網(wǎng)絡(JiuDay)
應該是這樣 你自己測試下