从Codeigniter中的帮助程序访问数据库配置变量 [英] Access database config variables from a helper in Codeigniter

查看:85
本文介绍了从Codeigniter中的帮助程序访问数据库配置变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从Codeigniter中的帮助器获取database.php变量值?

Is it possible to get the database.php variables values from a helper in Codeigniter?

推荐答案

通常你不能在帮助程序中使用 $ this ,所以你必须使用 get_instance()。我给了一个'主机名'的例子,你可以使用你需要的配置名称。

Here is the way, normally you won't be able to use $this in helper, so you have to use get_instance(). I have given an example of 'hostname' you can use the config name you need.

   function test()
    {
        $CI =& get_instance();
        $CI->load->database();
        echo $CI->db->hostname; // give the config name here (hostname).
    }

这篇关于从Codeigniter中的帮助程序访问数据库配置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆