【发布时间】:2018-05-30 09:40:18
【问题描述】:
我编写了一个返回数据的代码,但我不断收到错误“调用 null 时的成员函数 setFunction()”...
我的服务..
public function enableNotification($user)
{
$user->setNotification(1);
$this->em->flush();
}
我的控制器..
public function enableNotificationAction()
{
$user = $this->getUser();
$this->container->get('my.route')->enableNotification($user);
return $this->success('', 'true');
}
【问题讨论】:
-
在您的代码中没有您调用
setFunction()的地方,请提供发生此错误的代码。 -
对不起 setFunction 实际上是 enableNotification..
-
考虑用实际的错误消息更新您的问题。如果它是 enableNotification 那么 my.route 不存在应该触发不同的错误。如果它是 setNotification 则意味着 $user 为空,这反过来意味着您没有登录。无论如何,拥有实际的错误消息可以减少相当多的猜测。
标签: php function symfony error-handling null