我试图更新实体类中的单个数据,但原则总是返回此错误----
错误:对非对象调用成员函数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;
    }

有人知道我在哪里犯了错误吗。
提前谢谢。

最佳答案

findBy方法返回数组。改为使用findOneBy

关于mysql - 错误:在非对象上调用成员函数setStats(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31871558/

10-16 11:46