开发者

Calling PHP from Rails with input and output

I am wanting to call a RAILS script within my php code base to avoid having to duplicate complicated business logic. I see that in PHP I can use passthru() but I'm not sure that is the best bet when returning more than a string back to the PHP function. I need to return back a hash/object of key/value pairs.开发者_如何学Python

I'll be using script/runner on the RAILS side so that I don't have to change anything in the RAILS code. I was hoping there would be a simpler way to do this but I'm finding very little documentation on the webs that relates to this. Thanks in advanced.

Peace, James


You can make your Rails script output a CSV data and then use PHP's fgetcsv to parse it into array. Of course, you'll have to modify your Rails code to output CSV, but it doesn't sound like a big change - just a couple of lines to convert your data into CSV. FasterCSV gem could help with that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜