我是CodeIgniter新手,我想使用CodeIgniter构建want风格的new服务。如何使用REST服务将数据发布到mysql并从中获取数据?我浏览了一个网站'tutplus',但它没有mysql数据库的解释。
发布于 2014-08-27 05:15:37
非常简单,创建一些控制器,例如:user.php在这个控制器上编写所有必要的方法,例如: getUserInfo(),getUser(),getAge(),并通过URL调用这些方法。要解决这个问题,建议:
https://ellislab.com/codeigniter/user-guide/general/controllers.html
https://ellislab.com/codeigniter/user-guide/general/routing.html
发布于 2014-08-27 05:20:31
实际上,在我正在做的项目中,我们使用RESTControllers,在github上有一个项目,它扩展了codeigniter控制器的所有REST功能:https://github.com/chriskacerguis/codeigniter-restserver
你所需要做的就是在代码中包含控制器上的文件并扩展新的控制器:
require(APPPATH.'/libraries/REST_Controller.php');
class system extends REST_Controller {
}
您还可以在自动加载库配置中包含REST控制器。此库打开4个基本的REST API,即GET、POST、PUT和DELETE
在您的代码中,控制器url应该声明为this,这样您就可以获得索引上的POST方法。
public function index_post()
{
// ...just some code example
$this->response($book, 201); // Send an HTTP 201 Created
}
如果需要索引上的get,则将其声明为GET方法:
public function index_get()
{
// ...just some code example
$this->response($book, 201); // Send an HTTP 201 Created
}
https://stackoverflow.com/questions/25505574
复制相似问题