我已经声明了一个在 service.yml 中有一些依赖的服务,例如:
content_helper:
class: Oilproject\ContentBundle\Helper\ContentHelper
arguments: ["@doctrine.orm.entity_manager", "@memcache.default"]
calls:
- [setMemcache, ["@memcache.default"]]
我的助手类:
private $em;
private $memcache;
public function __construct(\Doctrine\ORM\EntityManager $em) {
$this->em = $em;
$this->memcache = $memcache;
}
public function setMemcache($memcache) {
$this->memcache = $memcache;
return $this;
}
//...
但是当我打电话时
$memcache = $this->memcache;
$contents = $memcache->get($key);
这次回归
Call to a member function get() on a non-object ...