【问题标题】:CodeIgniter REST_Controller POST method returning GETCodeIgniter REST_Controller POST 方法返回 GET
【发布时间】:2018-05-25 00:54:13
【问题描述】:

我在我的项目中使用REST_Controller CodeIgniter 库。

我有一个无法访问的登录发布方法,因为 REST_Controller 将方法设置为 GET,即使我执行 POST

这是我的 Auth.php 控制器的 sn-p:

defined('BASEPATH') OR exit('No direct script access allowed');

require_once APPPATH . '/core/REST_Controller.php';

class Auth extends REST_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    public function login_get()
    {
        echo('get');
    }

    public function login_post()
    {
        echo('post');
    }
}

当我在http://localhost/auth/login 使用RESTED Google Chrome 扩展程序执行POST时,我得到了echo('get')

调试 REST_Controller 我可以看到函数 _detect_method() 正在以 GET 的形式返回方法,这是因为在 Inputmethod() /em> CodeIgniter $this->server('REQUEST_METHOD') 的核心类正在返回 GET

为什么会这样?

【问题讨论】:

    标签: rest api codeigniter post get


    【解决方案1】:

    没关系,我找到了解决方案!

    发生这种情况只是因为我忘记在我的 Apache 中启用 mod_rewrite

    这解决了问题:

    sudo a2enmod rewrite
    sudo service apache2 restart
    

    【讨论】:

    • 奇怪!!它应该向您显示 404 错误。因为你的 mod_rewrite 被禁用并且你的 URL 没有 index.php like,http://localhost/index.php/auth/login
    • @jagad89,真的。我不知道为什么我没有 404。如果我得到了,会更容易知道这是一个 mod_rewrite 问题。
    猜你喜欢
    • 2015-03-30
    • 1970-01-01
    • 2015-11-24
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    相关资源
    最近更新 更多