如何最好地将移动服务与 CodeIgniter 集成?
我有一个基于 CodeIgniter 框架构建的网站。它实现了MVC架构。
我的困境是:我正在开发手机应用程序。一些研究告诉我,移动应用程序无法直接连接到 MySQL 数据库,因此,我需要在两者之间有一个服务层 - 在我的例子中,它们将是 PHP 脚本。
我是否可以(并且应该)将这些脚本集成到我的 MVC 架构中。如果是,我该怎么办?
目前,我想到的是:
- 移动应用程序向控制器发出 POST 请求 控制器
- 通过模型从数据库获取数据
- 控制器将数据编码为 JSON 并将其发送回移动应用程序
这是实现它的正确方法吗?
这是我第一次实现这样的事情,所以我想确保我没有错过任何东西。
I have a website that I built on the CodeIgniter framework. It implements the MVC architecture.
My dilemma is: I am developing applications for mobiles. A little research told me that mobile apps cannot connect directly to MySQL databases and thus, I need to have a service layer in between - in my case, they will be PHP scripts.
Is it possible (and should I) for me to integrate these scripts into my MVC architecture. If yes, how should I go about it?
Currently, I have this in mind:
- Mobile app makes POST request to a controller
- Controller gets data from the db via the Model
- Controller encodes data in JSON and sends back to mobile app
Would that be the correct way to implement it?
This is my first time implementing something like this so I want to make sure I'm not missing something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更好的是,创建一个完整的 REST 服务器供您的移动应用程序使用。您可以通过本教程了解它是多么容易:
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/
这也将有一个到库的链接,
Better yet, create a full REST server for your mobile app to use. You can get an idea of how easy it is with this tutorial:
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/
This will have a link to the library as well,
你是对的,我建议你在将数据编码为 JSON 之前对数据进行加密,如果数据安全的话,在移动设备上对其进行解码
还可以测试是否来自移动设备的请求,您可以通过随请求发送参数并在服务器上检查它以避免直接访问来实现这一点
祝你好运
You are right and I suggest that you encrypt the data before encoding it as JSON and decode it on the mobile if the data is secure
and also test weather the the request from a mobile device or not you can achieve this by sending parameters with the request and check it on the server to avoid direct access
Good Luck