【问题标题】:Unable to integrate Redis with Codeigniter无法将 Redis 与 Codeigniter 集成
【发布时间】:2013-08-08 08:54:55
【问题描述】:

我正在使用codigniter-redis 库在codeigniter 框架中使用redis。我已将Redis.php( 库文件) 放在应用程序/库中,将redis.php( 配置文件) 放在应用程序/配置中

这是我的代码

class Test extends Controller {

    function __construct()
    {
        log_msg('info', "loading redis");
        $this->load->library('redis', array('connection_group' => 'default'), 'redis_default');
    }

    function index()
    {
        $this->redis->command('PING');
    }

当我从浏览器调用测试控制器时,它给了我错误

Message: Undefined property: Test::$redis

Filename: controllers/test.php  

但它在日志文件中显示了适当的日志,一个如上所示,一个我放入 Redis.php 函数 _construct 告诉我连接成功

if ( ! $this->_connection)
        {
            show_error('Could not connect to Redis at ' . $config['host'] . ':' . $config['port']);
        }
        else
        {
            log_msg('info', "connection successful");
        }

【问题讨论】:

    标签: php codeigniter redis codeigniter-2


    【解决方案1】:

    请仔细检查一下:您在此处发布的代码与控制器完全相同吗? 如果是这样,请记住从 CI_Controller 扩展,而不仅仅是 Controller。

    另外,在 _construct() 中,你缺少你的父级::_construct()。

    从你的日志条目来看,它表明它正在 _construct() 上连接,但这基本上是它结束的地方。很可能是由于缺少父对象::_construct()。希望这会有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 2016-01-26
      相关资源
      最近更新 更多