2017-07-03 45 views
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); 

我有我的數據庫更新,請大家幫幫我。

+0

'getRepository('Mybundle')' - 應該傳遞類名'getRepository('Mybundle:Clinic')' –

+0

是的,當然。我寫了getRepository('MyBundle'),寫得更短。 。 –

+0

您是否嘗試過僅爲[主請求](http://symfony.com/doc/current/event_dispatcher.html#request-events-checking-types)應用您的邏輯,例如就像把你的邏輯包裝在'if(!$ event-> isMasterRequest()){0}中? – lordrhodos

回答

0

如果$c在您的第一個呼叫中設置,則稱爲$clinic的變量從不設置,但用於路由器調用。

+0

這是我的快捷方式,我必須編輯帖子,對不起:) –