简体   繁体   English

在Codeigniter中发布来自远程数据库查找的结果

[英]Posting results from remote DB lookup in codeigniter

I have a small 'distributed' system based on 2 servers . 我有一个基于2个服务器的小型“分布式”系统。 app A is written in python and I would like it to access a controller in my base program B (written in codeigniter). 应用程序A用python编写,我希望它访问我的基本程序B中的控制器(用codeigniter编写)。 I have written the following controller 'data_controller' in B containing: 我在B中编写了以下控制器'data_controller',其中包含:

function index()
{

       $t = R::findOne('times');
       $postArray = $t->export();

}

I'm using the redbeanphp ORM. 我正在使用redbeanphp ORM。 The code above picks a single record from the db and turns the row into an key-value array. 上面的代码从数据库中选择一条记录,并将该行转换为键值数组。 I want to http Post this to App A by letting A open: 我想通过让A打开来将其发布到App A:

http:localhost/appB/index.php/data_controller

what do I need to do next to send the content of $postArray to App A 将$ postArray的内容发送到App A下一步需要做什么

You could output the data as JSON and have Python decode the data . 您可以将数据输出JSON并让Python 解码数据 You can output the data as JSON from CodeIgniter like this: 您可以像这样从CodeIgniter将数据输出为JSON:

header('Content-Type: application/json;');
echo json_encode($postArray);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM