0
我有我的方法getDomain()監守我報告一個問題,,調用一個成員函數上的空getDomain()「」Symfony3 - 錯誤與我的方法getDomain()
這是我的實體.. ..
class Clinic
{
.............
/**
* @ORM\Column(type="string")
*/
private $domain;
..............
/**
* @return string
*/
public function getDomain()
{
return $this->domain;
}
/**
* @param string $domain
*/
public function setDomain($domain)
{
$this->domain = $domain;
}
...............
,這是我的EventListener
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
$currentHost = $request->getHttpHost();
$c = $this->em
->getRepository('Mybundle:Clinic')
->findOneBy(['domain' => $currentHost]);
if (!$c) {
$c = $this->em
->getRepository('Mybundle:Clinic')
->findOneBy(['domain' => $this->baseHost]);
}
$this->router->getContext()->setParameter('_domain', $c->getDomain());
$this->cManager->setCC($c);
我有我的數據庫更新,請大家幫幫我。
'getRepository('Mybundle')' - 應該傳遞類名'getRepository('Mybundle:Clinic')' –
是的,當然。我寫了getRepository('MyBundle'),寫得更短。 。 –
您是否嘗試過僅爲[主請求](http://symfony.com/doc/current/event_dispatcher.html#request-events-checking-types)應用您的邏輯,例如就像把你的邏輯包裝在'if(!$ event-> isMasterRequest()){0}中? – lordrhodos