【问题标题】:Setting up Codeigniter HMVC with tank auth使用 tank auth 设置 Codeigniter HMVC
【发布时间】:2011-11-06 13:24:03
【问题描述】:

我无法正确设置具有 hmvc 和 tank auth(设置为模块)的工作 Codeigniter 版本 2.0.3。我已经正确安装了 CI,然后按照这些说明安装 HMVC https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home

我以我的欢迎控制器/视图为例就好了,这意味着 HMVC 正在工作。接下来,我尝试通过将 tank auth 添加到模块文件夹中的文件夹来将其添加到项目中。它具有适当的控制器/视图/模型等。在坦克身份验证中设置。我什至在路线中添加了类似

$route["auth"]="auth/login";

我还按照指示将 auth 模块中的控制器扩展为 MX_Controller。我也在构造函数中:

$this->load->helper(array('form', 'url'));
    $this->load->library('form_validation');
    $this->load->library('security'); <--failing to load this

    $this->load->library('tank_auth');
    $this->lang->load('tank_auth');
     $this->form_validation->CI =& $this;

它似乎可以很好地重定向到模块但是它出现了一个错误说::

遇到错误

无法加载请求的类:安全性

我做错了什么?是否有人将 HMVC 和 tank auth 作为模块进行了有效的 CI 安装,所以我可以看到它是如何完成的?我是 HMVC 新手,谢谢

【问题讨论】:

  • 库文件夹中是否存在security.php文件?
  • security.php 是 codeigniter 本身的一部分,因此它不位于 modules/auth/libraries/... 文件夹中。我是否必须获取 CI 的实例才能在模块控制器的构造函数中调用其库/助手?
  • 所以我改了 $this->load->library('security');到 $this->load->helper('security');现在出现了一个新错误,我想当它尝试加载tank_auth库时,说找不到配置文件tank_auth.php..虽然有modules/modulename/config/tank_auth.php完好无损。不知道为什么它会找到它,但我假设它类似于我的其他问题
  • CodeIgniter 中有不同种类的安全文件,其中一种是帮助程序,另一种用于在提交到数据库时对数据进行转义。
  • 原来的 tank auth 需要库 security 而不是 helper,tank auth 只使用 CI 的原生安全库,不提供自己的

标签: codeigniter hmvc tankauth


【解决方案1】:

我阅读了 CodeIgniter 3.X 用户指南,发现“安全”现在可以作为“助手”使用。

所以你需要改变它;

$this->load->library('security');

进入

$this->load->helper('security');

XSS 过滤

Input 类能够自动过滤输入以防止跨站点脚本攻击。如果您希望过滤器在每次遇到 POST 或 COOKIE 数据时自动运行,您可以通过打开您的 application/config/config.php 文件并设置它来启用它:

$config['global_xss_filtering'] = TRUE;

您需要阅读 CodeIgniter 3.0 用户指南,其中有很多更改和实施或请参阅更改日志。

【讨论】:

    【解决方案2】:

    现在根据CodeIgniter 3.0 user guide在Helper中

    尝试:

    $this->load->helper('security');
    

    【讨论】:

    • 所以你的意思是这是助手而不是库
    【解决方案3】:

    Security.php 存在于“codeigniter/system/core/Security.php”中 所以提供这条路径你的问题很容易解决

    load->library('../core/security');
    

    【讨论】:

      【解决方案4】:
      • 将文件security.phpsystem/core移动到system/libraries

      • 然后将core/codeigniter.php第204行从$SEC =&amp; load_class('Security', 'core');编辑为$SEC =&amp; load_class('Security', 'libraries');

      【讨论】:

        【解决方案5】:

        我通过使用以下代码在application/libraries 目录中创建Security.php 文件来解决此问题:

        require_once(BASEPATH.'core/Security.php');
        
        class Security extends CI_Security { }
        

        【讨论】:

          【解决方案6】:

          我发现了同样的问题,但我通过简单地添加评论解决了

          $this->load->library('security');
          

          所以它看起来像这样:

          //$this->load->library('security');
          

          由于安全性现在是 codeigniter 核心的一部分,我猜它已经默认加载,一切似乎都运行良好

          【讨论】:

          • 试试这个:$this->load->helper('security');
          • 并将$this-&gt;security-&gt;xss_clean();替换为`xss_clean();
          【解决方案7】:

          我找到了解决方案,我只是从 codeigniters 系统/核心文件夹中取出 security.php 文件并将其放入系统/库中。

          【讨论】:

            猜你喜欢
            • 2011-09-11
            • 1970-01-01
            • 2011-04-24
            • 1970-01-01
            • 2011-10-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多