系统的设置功能

Original 2019-04-09 16:07:02 353
abstract:<?phpnamespace app\admins\controller;use think\Controller;use Util\SysDb;class Setting extends Base{ // 网站设置 public function index(){ $data['item'] = $this->db->table('setting

<?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);

}

return $this->fetch('',$data);

}


public function save(){

$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'=>'保存成功')));

}

}


Correcting teacher:天蓬老师Correction time:2019-04-10 10:23:19
Teacher's summary:在ThinkPHP中, 后端的返回内容类型,默认就是json, 不必再转换了

Release Notes

Popular Entries