上一章我们学习了栏目的开发,那么这一章我们主要学习什么呢?
这一章我们开始实现系统设置功能【网站的基本信息设置】
修改图如下:
那么数据库表的设计,表名为tp_config 基本设置
- id
- webname 网站名称
- webtitle 网站标题
- weblogo 网站LOGO
- webkey 网站关键字
- webdes 网站描述
- personname 网站联系人
- tel 电话
- address 地址
- icp 备案号
- email 邮箱
- qq QQ
- msn MSN
- copyright 版权
- tongji 统计
- wechat 微信号
- lang 语言 【cn,en】
- cutdown 倒计时
在Application\Admin\Controller控制器中添加ConfigController.class.php文件
// 站点设置
public function index(){
if($_SESSION['adminUser']['lang'] == 'cn'){
$where['id'] = 1;
}else if($_SESSION['adminUser']['lang'] == 'en'){
$where['id'] = 2;
}
$where = array(
'lang' => $_SESSION['adminUser']['lang']
);
$res = D('Setting')->getInfo($where);
$this->assign('info',$res);
$this->display();
}
// 处理动作
public function addHandle(){
$data = I('post.');
if(!$data['webname']){
return show(0,'网站名称不能为空');
}
if(!$data['webtitle']){
return show(0,'网站标题不能为空');
}
$where = array(
'lang' => $_SESSION['adminUser']['lang'],
'id' => $data['id']
);
$res = D('Setting')->updateInfo($data, $where);
if($res){
return show(1,'操作成功');
}else{
return show(0,'操作失败');
}
}
在Application\Common\Model模型目录中添加SettingModel.class.php文件, 代码如下:
/**
* @Author: 穆沂华
* @Date: 2017-09-28 16:23:32
* @Last Modified by: 穆沂华
* @Last Modified time: 2017-09-28 16:23:32
*/
namespace Common\Model;
use Think\Model;
class SettingModel extends Model{
private $_db = '';
public function __construct(){
$this->_db = M('config');
}
/**
* 通过条件进行数据查询
* @param $where
* @return mixed
*/
public function getInfo($where){
$res = $this->_db->where($where)->find();
return $res;
}
/**
* 更新站点信息
* @param array $data
* @param $where
* @return bool
*/
public function updateInfo($data=array(), $where){
if(!$data || !is_array($data)){
throw_exception('数据有误');
}
$res = $this->_db->where($where)->save($data);
return $res;
}
}
注:网站基本信息设置是固定不变的,所以没有添加功能,直接进行条件更新数据库信息即可,还有这个除了写进数据库表中,可以写入文件,或者缓存中,这块自己探讨~~~
这一章先开发到此,待续~~~~