【问题标题】:Error with multiple params in entity, symfony2实体中的多个参数错误,symfony2
【发布时间】:2016-03-07 15:55:46
【问题描述】:

我给出了以下错误:

Catchable Fatal Error: Argument 1 passed to BackendBundle\Entity\Notification::sendSystemMessage() 
must be an instance of BackendBundle\Entity\BackendBundle\Entity\User, instance of 
Proxies\__CG__\BackendBundle\Entity\User given

我在 Notification.php 类中的方法是:

/**
     * Send System message, to be used after creating a blank one
     *
     * @param \BackendBundle\Entity\User $reciever
     *
     * @param string $message
     *
     * @return Notification
     */
    public function sendSystemMessage(BackendBundle\Entity\User $reciever, $message)
    {
        $this->setReciever($reciever);
        $this->setMessage($message);
        $this->setTimestamp(new \DateTime());
        $this->setReaded(false);
        $this->setSystemMessage(true);

        return $this;
    }

当我使用像 setReciever 这样的 setter 和 getter 时,它工作得很好,但是当我尝试调用多个参数时,我得到了这个错误,我犯了一个错误,或者实体中不能有一个多参数方法上课?

【问题讨论】:

  • 该错误消息来自其他地方的代码,您可以在其中调用 sendSystemMessage() 函数。您的 $reciever 参数类型错误。
  • 这是我的第一个想法,但我调用 setReciever 方法进行了相同的验证,效果很好
  • 什么意思?您能否显示将两者与发送的相同参数以及 setReciever 的函数描述进行比较的代码?
  • 在用户类型提示的开头添加反斜杠。更好的是,添加一个 use 语句并简化对 User 的类型提示。 php.net/manual/en/language.namespaces.php
  • 这就是问题所在,该死的反斜杠,谢谢!

标签: php symfony parameters doctrine symfony-2.8


【解决方案1】:

感谢 Cerad。

我的问题是我有

public function sendSystemMessage(BackendBundle\Entity\User $reciever, $message)

当我需要时

public function sendSystemMessage(\BackendBundle\Entity\User $reciever, $message)

那个反斜杠让我为 User 类提供了不同的路径

【讨论】:

    猜你喜欢
    • 2018-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多