摘要:<?phpnamespace app\admins\controller;use think\Controller;use Util\SysDb;class Setting extends Base{ public function index() { $data['item
<?php
namespace app\admins\controller;
use think\Controller;
use Util\SysDb;
class Setting extends Base
{
public function index()
{
$data['item'] = $this->db->table('setting')->where(array('names'=>'site_setting'))->item();
if($data['item']){
$data['item']['values'] = json_decode($data['item']['values'],true);
//把json格式變成數(shù)組
}
return $this->fetch('',$data);
}
public function save()
{
//接收什么數(shù)據(jù)
$names = trim(input('post.names'));
$data['values'] = json_encode(input('post.values'));
//判斷是保存還是修改
$item = $this->db->table('setting')->where(array('names'=>$names))->item();
if($item){
$this->db->table('setting')->where(array('names'=>$names))->update($data);
}else{
$data['names'] = $names;
$this->db->table('setting')->insert($data);
}
exit(json_encode(array('code'=>0,'msg'=>'保存成功')));
}
}
批改老師:查無(wú)此人批改時(shí)間:2019-04-19 09:34:11
老師總結(jié):完成的不錯(cuò)。這個(gè)模塊,可以繼續(xù)增加功能。繼續(xù)加油。