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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog