thikphp 简单的接口骨架

//get id 获取内容,调用xml方法
public function get(){
$id = $_GET['id'];//接收id
$User = M('user');
//$val->where("id = $id")->select();
$data=$User->where( "id = $id" )->find();
$this->arrtoxml($data);
//dump($val);
//dump($id);
}


//封装成xml
public function arrtoxml($data,$dom=0,$item=0){
if (!$dom){
$dom=new DOMDocument("1.0");
}
if(!$item){
$item=$dom->createElement("cti");
$dom->appendChild($item);
}
foreach ($data as $key=>$val){
$itemx=$dom->createElement(is_string($key)?$key:"item");
$item->appendChild($itemx);
if (!is_array($val)){
$text =$dom->createTextNode($val);
$itemx->appendChild($text);

}else{
$this->arrtoxml($val,$dom,$itemx);
}

}

header('Content-Type:text/xml');
dump($dom->saveXML());
}


//get id 获取内容,调用json方法
public function find(){
$id = $_GET['id'];//接收id
$User = M('user');
//$val->where("id = $id")->select();
$data=$User->where( "id = $id" )->find();
$this->json($data);
//dump($val);
//dump($id);
}


//封装json方法
public function json($data){
foreach($data as $key=>$value){
$jobj->$key=$value;
}
//print_r($jobj);//打印传递属性后的对象
//echo '使用$jobj->row[0][\'code\']输出数组元素:'.$jobj->row[0]['code'].'<br>';
echo '编码后的json字符串:'.json_encode($jobj).'<br>';//打印编码后的json字符串

}


//get id and account 获得内容并显示出来
public function un(){
$account = $_GET['account'];//接收account
$id=$_GET['id'];//接收密码
$User = M('user');


//$condition = new stdClass(); 
$condition['account'] = $account;
$condition['id'] = $id;


//$val->where("id = 1")->select();
$User->where($condition)->find();
//$this->json($data);
dump($_GET);
dump($User);
dump($condition);
}


//get account and password,调用json方法
public function up(){
$account = $_GET['account'];//接收account
$password=$_GET['password'];//接收密码
$User = M('user');


//$condition = new stdClass(); 
$condition['account'] = $account;
$condition['password'] = $password;


//$val->where("id = 1")->select();
$data=$User->where($condition)->find();
//$this->json($data);
//dump($_GET);
//dump($User);
//dump($condition);

$this->json($data);
}

 

 

http://localhost/rbac/Public/up?account=admin&password=admin 改进

转载于:https://www.cnblogs.com/hellowzd/p/4150955.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值