如何在 Codeigniter 中编写 Web 服务?

How to write web services in Codeigniter?

我使用的是 Codeigniter 版本 2。在我的项目中,我遵循 HMVC 模式。但是现在我想编写 REST api web 服务。对于 Web 服务,我下载了库 REST_Controller.php。

添加库后,根据 HMVC 模式为 wirte web 服务创建一个文件夹。在 webservices class 中创建函数后,我必须以这种格式 url 编写 http://localhost/project_name/index.php/webservices/login

但我不想要这种格式的 url 我想要下面的格式 http://localhost/amoeba/webservices/login。请建议我如何在 Codeigniter 中编写 Web 服务。

您需要修复您的 .htaccess 文件。

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond  !^(index\.php|images|robots\.txt|css|docs|js|system)
RewriteRule ^(.*)$ index.php?/ [L]