若上一篇不够清晰,这是第二个例子。
1):表
2):
3):
<?php
namespace appsanwudaichaocontroller;
use thinkController;
use thinkDb;
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:OPTIONS, GET, POST'); // 允许option,get,post请求
header('Access-Control-Allow-Headers:x-requested-with'); // 允许x-requested-with请求头
header('Access-Control-Max-Age:86400'); // 允许访问的有效期
class Bank extends Controller
{
// 连接
private $dbcon;
public function __construct(){
// $this->dbcon = Db::connect("mysql://root:@127.0.0.1:3306/test#utf8");
$this->dbcon = Db::connect(".......");
}
public function getBankInfo(){
$id = $_POST['xly'];
if($id==1){
$arr=array();
$proInfo = $this->dbcon->table('bank')->select();
foreach ($proInfo as $key => $value) {
$temp=array();
$imgSrc=$value['bank_img'];
$intr=$value['bank_introduction'];
$name=$value['bank_name'];
$link=$value['bank_link'];
$earn=$value['bank_earn'];
$passrate=$value['passingrate'];
$applynum=$value['applynum'];
array_push($temp, $imgSrc,$intr,$name,$link,$earn,$passrate,$applynum);
array_push($arr, $temp);
// array_push($arr,$temp);
// array_push(array, var)
}
$arr_json=json_encode($arr);
echo $arr_json;
}
}
}