Files
SRCMS/Application/User/Controller/InfoController.class.php

85 lines
2.3 KiB
PHP
Raw Normal View History

2015-10-06 20:25:13 +08:00
<?php
namespace User\Controller;
use Think\Controller;
/**
* @author Zhou Yuyang <1009465756@qq.com> 12:21 2016/1/26
* @copyright 2105-2018 SRCMS
2015-10-06 20:25:13 +08:00
* @homepage http://www.src.pw
* @version 1.6
2015-10-06 20:25:13 +08:00
*/
class InfoController extends BaseController{
public function index(){
$id = session('userId');
$tmodel= M('setting');
$title = $tmodel->where('id=1')->select();
2015-10-06 20:25:13 +08:00
$info = M('info')->where('user_id='.$id)->select();
$this->assign('title', $title);
2015-10-06 20:25:13 +08:00
$this->assign('info',$info);
$this->display();
}
/**
* 添加联系方式
*/
public function add()
{
//默认显示添加表单
if (!IS_POST) {
$this->display();
}
if (IS_POST) {
//如果用户提交数据
$model = D("info");
$model->user_id = 1;
$model->username = 1;
if (!$model->field('realname,zipcode,location,tel,alipay')->create()) {
2015-10-06 20:25:13 +08:00
// 如果创建失败 表示验证没有通过 输出错误提示信息
$this->error($model->getError());
exit();
} else {
if ($model->add()) {
$this->success("添加成功", U('info/index'));
} else {
$this->error("添加失败");
}
}
}
}
/**
* 更新联系方式
*/
public function update()
{
//默认显示添加表单
$id = session('userId');
2015-10-06 20:25:13 +08:00
if (!IS_POST) {
$info = M('info')->where('user_id='.$id)->select();
$this->assign('info',$info);
2015-10-06 20:25:13 +08:00
$this->display();
}
if (IS_POST) {
//如果用户提交数据
$model = D("info");
$model->user_id = 1;
$model->username = 1;
if (!$model->field('realname,zipcode,location,tel,alipay')->create()) {
2015-10-06 20:25:13 +08:00
// 如果创建失败 表示验证没有通过 输出错误提示信息
$this->error($model->getError());
exit();
} else {
if ($model->save()) {
$this->success("联系方式更新成功", U('info/index'));
2015-10-06 20:25:13 +08:00
} else {
$this->error("联系方式更新失败");
2015-10-06 20:25:13 +08:00
}
}
}
}
}