基本信息
源码名称:thinkphp 入门实例源码(增删改查)下载
源码大小:1.05M
文件格式:.rar
开发语言:PHP
更新时间:2017-01-07
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
//展示页面
public function index(){
$house=M("json");
$res= $house->select();
$url="http://api.map.baidu.com/telematics/v3/weather?location=%E6%B7%B1%E5%9C%B3&output=json&ak=nfczRD5nihKuHViUZ8ggkUGC";
//获得网站的JSON数据
$data=file_get_contents($url);
//把josn数据转化为数组
$json=json_decode($data,true);
//获得一个二维数组
$arr=$json['results']['0']['index'];
//dump($arr=$json['results']['0']['index']);
//dump($json['results']);
//转化为一位数组
foreach ($arr as $key => $v) {
//只取2个字段加入数据库, 有很多字段不用全部加
$data=array(
"title"=> $v['title'],
"tipt"=> $v['tipt'],
);
}
$house->add($data);
$this->assign("res",$res);
$this->display();
}
//增加界面
public function add(){
$this->display();
}
public function addpro(){
$house=M("json");
$data=array(
'tipt' =>I("post.tipt"),
'title' =>I("post.title"),
);
if($house->data($data)->add()){
$this->success('增加成功', 'index');
}else{
$this->error("增加失败");
}
}
//修改
public function edit(){
$house=M("json");
$id=I("get.id");
$data=array(
"id"=>$id
);
$res= $house->where($data)->find();
$this->assign("res",$res);
$this->display();
}
public function editpro(){
$house=M("json");
$data=array(
"id"=>I("post.id"),
'tipt' =>I("post.tipt"),
'title' =>I("post.title"),
);
if($house->data($data)->save()){
$this->success('修改成功', 'index');
}else{
$this->error("修改失败");
}
}
//删除
public function del(){
$id=I("get.id");
$house=M("json");
$data=array(
"id"=>$id
);
if($house->where($data)->delete()){
$this->success('删除成功', 'index');
}else{
$this->error("删除失败");
}
}
}