auth_override_class_method_http不适用于HMVC

嗨,我有如下配置设置:

$config['auth_override_class_method_http']['admin']['auth']['post'] = 'none';

我正在为我的HMVC使用此库:https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

但是当我检查REST_Controller.php上的错误处理时

似乎REST无法识别/ admin / auth

这是我的REST代码:

<?php
use Restserver\libraries\REST_Controller;
defined('BASEPATH') OR exit('No direct script access allowed');
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
/** @noinspection PhpIncludeInspection */
//To Solve File REST_Controller not found
require APPPATH . 'libraries/REST_Controller.php';
require APPPATH . 'libraries/Format.php'; 

class Auth extends REST_Controller {

    function __construct()
    {
        // Construct the parent class
        parent::__construct(); 

        $this->load->model('Auth_model','Entity_model');
        //$this->load->library('form_validation');
        $this->load->library('validation');

        header('access-control-allow-origin: *');
        header("access-Control-Allow-Methods: GET,POST,OPTIONS,PUT,DELETE");



    }


    public function index_get()
    { 


      $return_message = [
                         'error' => 102,'message' => "Entity Not Found"
                        ];
      $this->set_response($return_message,REST_Controller::HTTP_NOT_FOUND);  

    }


    public function index_post()
    {
        /* Request,Response https://i.vgy.me/APy9PT.png */


            $message = [
                'status' => true,'error_code' => 102,'error_message' => 'success'
            ];

            $this->set_response($message,REST_Controller::HTTP_CREATED); 
            // CREATED (201) being the HTTP response code

    }



}

尽管我所有的GET / POST请求都可以正常工作,因为它应该在端点上。

有人能建议我该怎么做才能使它工作,即

我想对多个API请求使用身份验证,但不希望对admin / auth [POST]

使用身份验证
aoyang110 回答:auth_override_class_method_http不适用于HMVC

经过几天的调试,我意识到由于我使用的是HMVC,REST_Controller中的路由器类未获得正确的索引。

所以我编辑了REST_controller以与HMVC一起使用

第1498行:添加

if ( ! empty($auth_override_class_method_http[$this->router->module][$this->router->class][$this->request->method]))
            {
                // None auth override found,prepare nothing but send back a TRUE override flag
                if ($auth_override_class_method_http[$this->router->module][$this->router->class][$this->request->method] === 'none')
                {
                    return TRUE;
                }

                // Basic auth override found,prepare basic
                if ($auth_override_class_method_http[$this->router->module][$this->router->class][$this->request->method] === 'basic')
                {
                    $this->_prepare_basic_auth();

                    return TRUE;
                }

                // Digest auth override found,prepare digest
                if ($auth_override_class_method_http[$this->router->module][$this->router->class][$this->request->method] === 'digest')
                {
                    $this->_prepare_digest_auth();

                    return TRUE;
                }

                // Session auth override found,check session
                if ($auth_override_class_method_http[$this->router->module][$this->router->class][$this->request->method] === 'session')
                {
                    $this->_check_php_session();

                    return TRUE;
                }

                // Whitelist auth override found,check client's ip against config whitelist
                if ($auth_override_class_method_http[$this->router->module][$this->router->class][$this->request->method] === 'whitelist')
                {
                    $this->_check_whitelist_auth();

                    return TRUE;
                }
            }
本文链接:https://www.f2er.com/3073119.html

大家都在问