我嘗試將memcached服務注入到實體存儲庫中,但是我的變體不起作用。Symfony 3將服務注入到實體存儲庫中
services:
work.repository.company:
class: WorkBundle\Repository\CompanyRepository
factory: ['@doctrine.orm.entity_manager', getRepository]
arguments:
- 'WorkBundle:Company'
calls:
- [setCacheService, ['@memcache.default']]
CompanyRepository具有setter setCacheService,但它不被調用。
class CompanyExtension extends \Twig_Extension
{
/**
* @var EntityManager
*/
private $em;
public function setEntityManager(EntityManager $entityManager)
{
$this->em = $entityManager;
}
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('getCompaniesCount', array($this, 'getCompaniesCount'))
);
}
/**
* @return integer
*/
public function getCompaniesCount()
{
return $this->em->getRepository('WorkBundle:Company')->getActiveCompaniesCount();
}
public function getName()
{
return 'work_company_extension';
}
}
爲什麼這段代碼不起作用?
不好的做法!像這樣顯示:[在symfony中使用memcached手動緩存資源 - 版本1](http://www.inanzzz.com/index.php/post/gbmc/manually-caching-resources-with-memcached-in-symfony-版本1)或[在symfony中使用memcached手動緩存資源 - 版本2](http://www.inanzzz.com/index.php/post/9pst/manually-caching-resources-with-memcached-in-symfony-版本-2) – BentCoder