user2818060
user2818060

Reputation: 845

how to acces object of memcached in php

what i need

code snippet

class Cache_model extends CI_Model {

public function __construct() 
{
            parent::__construct ();
            $this->load->model('memcache_model'); 
            $m = new Memcached();
             $m->addServer('localhost', 11211);
        $this->load->driver('cache', array('adapter' => 'memcached', 'backup' => 'file'));
}

     // function that works

     public function getCatLevelInfo($cat_id, $cat_index)
{
    $Data = array();
  $m = new Memcached();
 $m->addServer('localhost', 11211);
 $cat_info = $m->get($cat_index.$cat_id);
}

 }


  // function that don"t works



public function getCatLevelInfo($cat_id, $cat_index)
{
    $Data = array();

 $cat_info = $this->get($cat_index.$cat_id);
}

Upvotes: 0

Views: 134

Answers (1)

Ilanus
Ilanus

Reputation: 6928

You need to declare your $m as global var try

<?php
/**
 * Created by PhpStorm.
 * User: Ilan Hasanov
 * Date: 1/7/2016
 * Time: 1:02 PM
 */
class Cache_model extends CI_Model {

    private $m = null;

    public function __construct()
    {
        parent::__construct();
        $this->load->model('memcache_model');
        $this->m = new Memcached();
        $this->m->addServer('localhost', 11211);
        $this->load->driver('cache', array('adapter' => 'memcached', 'backup' => 'file'));
    }

    // function that works

    public function getCatLevelInfo($cat_id, $cat_index)
    {
        $cat_info = $this->m->get($cat_index.$cat_id);
        var_dump($cat_info);
    }
}

Upvotes: 2

Related Questions