2
我使用Symfony 1.4,Doctrine 1.2和sfDoctrineGuardPlugin。在我的actions.class.php有:如何正確獲取ID?
$this->idsfguard = $this->getUser()->getGuardUser()->getId();
,如果我在這工作好我登錄,但如果然後我退出,我有錯誤:
Fatal error: Call to a member function getId() on a non-object in
我想:
if ($this->getUser()->getGuardUser()->isAuthenticated()){
$this->idsfguard = $this->getUser()->getGuardUser()->getId();
}
但我有錯誤:
Fatal error: Call to a member function isAuthenticated() on a non-object in
謝謝!現在在模板成功我應該使用isset($ id)相同在清除php?在symfony做不同? –
@Beded Black:isset()很好。只要確保將變量作爲「$ this-> id」傳遞給模板,然後可以執行isset($ id)。 – Tom