douweng7308 2014-03-28 09:40
浏览 31
已采纳

如何在命名空间的应用程序中使用memcache?

I want to use memcache into my application. I have enabled php_memcache.dll in php.ini file and normal memcache is working fine in simple PHP.

$memcache = new Memcache;
$memcache->connect('localhost', 11211);
$test = $memcache->get("A");
if(empty($test)){
       echo "setting cache";
       $memcache->set("A","Cache contents",MEMCACHE_COMPRESSED,50);
}
echo $test;

But I don't know how to create object for Memcache in Zend Framework 2 for normal Memcache, when I am trying to shows error as:

Fatal error: Class 'Application\Controller\Memcache' not found

Please help me to solve my problem.

  • 写回答

1条回答 默认 最新

  • douzi9211 2014-03-28 09:47
    关注

    It seems you are trying to initialize Memcache object from your controller, which is in Application\Controller namespace. In this case, it looks for Memcache in the same namespace. You need to refer it from global namespace as:

    $memcache = new \Memcache;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?