错误:在非对象上调用成员函数setStats()

时间:2015-08-07 07:03:36

标签: mysql symfony doctrine entity

我正在尝试更新我的实体类中的单个数据,但该学说总是返回此错误----

错误:在非对象上调用成员函数setStats()

        $em = $this->getDoctrine()->getManager();

        $result = $em->getRepository('MyBundle:UserStats')->findBy(array('ownerPhone' => 1002));

        if( isset($result) && $result !== false ) {
        echo $result->setConditionState(0); // ConditionState is a boolean condition which i want to set it to false

        }
        $em->flush();

我的实体类为conditionState ---

/**
     * Set conditionState
     *
     * @param boolean $conditionState
     *
     * @return UserStats
     */
    public function setConditionState($conditionState)
    {
        $this->conditionState = $conditionState;

        return $this;
    }

    /**
     * Get conditionState
     *
     * @return boolean
     */
    public function getConditionState()
    {
        return $this->conditionState;
    }

有人知道我在哪里弄错了。 谢谢你提前。

1 个答案:

答案 0 :(得分:2)

findBy方法返回一个数组。请改用findOneBy