zoukankan      html  css  js  c++  java
  • CI框架在辅助函数中使用配置文件中的变量

    问题:

      现有一个自定义的辅助函数,想要获取配置文件中的配置项(配置文件路径为application/config/config.php)

    分析:

      辅助函数并不是定义在一个class中,而是很多个可供外部调用的API(function)而已,也就说,不能直接使用$this->config->item("index")来获取index配置项的值。

      如果强制使用$this->config->item("index")来获取index配置项的值时,会触发如下错误:

      Using $this when not in object context ..........

      所以$this->config->item()的形式要在class中使用,即使你手动载入config.php,那也是一样的错误,因为配置文件是自动加载的。

    解决方案一:

      后来翻手册,找到一个config_item('index')函数,可以在全局访问配置文件中的变量值。

    解决方案二:

      使用$ci = &get_instance;获得一个codeigniter对象,然后可以通过$ci->config->item('index')来获取配置项

  • 相关阅读:
    python3 flask 文件下载服务器
    jquery cdn加速
    cherry 与sqlite
    cherry 与react.js
    cherrypy json 解析
    cherrypy cookies
    cherrypy 打印日志
    cherrypy pytest 覆盖,测试代码
    cherrypy ajax 请求
    cherrypy 访问css文件
  • 原文地址:https://www.cnblogs.com/-beyond/p/7977349.html
Copyright © 2011-2022 走看看