摘要:作业总结:这次跟老师有点不同,是提交的时候插入数据,我是当进入这个页面的时候自动生成id为1的空数据,然后用更新来替换数据。<?php namespace app\admin\controller; use app\admin\model\System as systemModel; use think\facade\Request; us
作业总结:
这次跟老师有点不同,是提交的时候插入数据,
我是当进入这个页面的时候自动生成id为1的空数据,然后用更新来替换数据。
<?php
namespace app\admin\controller;
use app\admin\model\System as systemModel;
use think\facade\Request;
use think\facade\Session;
use think\Controller;
class System extends Controller
{
public function lst()
{
// 从数据库中获取id为1的数据
$data=systemModel::get(1);
// 如果数据存在,则输出到模板
if ($data!==null) {
$this->view->data=$data;
}else{
// 如果数据不存在,则创建id为1的空数据,并输出到模板
systemModel::create([
'net_name'=>"",
'title'=>"",
'content'=>"",
'co_title'=>"",
'co_content'=>"",
'ad_title'=>"",
'ad_content'=>"",
]);
$data=systemModel::get(1);
$this->view->data=$data;
}
return $this->fetch();
}
public function doedit()
{
// 获取异步提交的数据
$data=Request::param();
// 更新到数据库
$result = systemModel::update($data);
if ($result) {
return ['res'=>1,'msg'=>'更新成功'];
}else{
return ['res'=>2,'msg'=>'更新失败'];
}
}
}
批改老师:韦小宝批改时间:2018-12-06 15:18:38
老师总结:系统模块其实不需要id也是可以的!因为一个网站中的系统信息只能有一份!