后台:
public function actionIndex()
{
return $this->render(‘index’);
}
public function actionSel()
{
$city=$_POST['city'];
$data=file_get_contents("http://api.k780.com/?app=weather.future&weaid=$city&&appkey=42763&sign=26460e6f3d493f76aeeeafa59896e8bb&format=json");
$data1=json_decode($data,true);
$arr=$data1['result'];
//入库
foreach($arr as $v){
$ct=$city;
$week=$v['week'];
$temp_low=$v['temp_low'];
$temp_high=$v['temp_high'];
$days=$v['days'];
$a=new tianqi();
$a->city=$ct;
$a->week=$week;
$a->temp_high=$temp_high;
$a->temp_low=$temp_low;
$a->days=$days;
$a->insert();
}
return $this->render('show',['city'=>$city,'data'=>$arr]);
}
前台:
查找页面:
展示页面:
效果: