系统设计控制器的实现

Original 2019-04-19 08:16:18 186
abstract:<?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格式变成数组
       }
       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-19 09:34:11
Teacher's summary:完成的不错。这个模块,可以继续增加功能。继续加油。

Release Notes

Popular Entries