我想在我的Repository中獲取當前的語言環境。這就是爲什麼我要將容器注入到Repository中,但出現錯誤,我無法弄清楚。 這是我service.yml
代碼在Entity Repository中注入容器
survey.repository.container_aware:
class: Demo\SurveyBundle\Repository\SurveyRepository
calls:
- [ setContainer, [ @service_container ] ]
,這是我的倉庫類代碼
.......
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
.......
protected $container;
public function __construct(Container $container) {
$this->container = $container;
}
之後,我收到以下錯誤
ContextErrorException: Catchable Fatal Error: Argument 1 passed to
Demo\SurveyBundle\Entity\SurveyRepository::__construct() must implement
interface Symfony\Component\DependencyInjection\ContainerInterface, instance of
Doctrine\ORM\EntityManager given
我很想念我的構建或服務?
爲什麼你要注入整個容器?請更精確地嘗試直接注入您所依賴的服務。 – Basster 2014-12-05 10:52:06