Symfony Doctrine entity friend hasFriend followers

偶尔善良 提交于 2019-12-04 17:25:42

The problem seems to be that you are comparing two different type variable.

When you do this: {% if (app.user.hasFriend(follower.nick)) %} the following function is called:

/**
 * 
 * @param \TB\UserBundle\Entity\User $user
 * @return bool
 */
public function hasFriend(User $user)
{
    return $this->myFriends->contains($user);
}

This function is called, taking a User type $user variable and you then use the contains() function on $this->myFriends.
$this->myFriends is an ArrayCollection of Requests (so different type than User) and from the doctrine documentation about contains():

The comparison of two elements is strict, that means not only the value but also the type must match.

http://www.doctrine-project.org/api/common/2.1/class-Doctrine.Common.Collections.ArrayCollection.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!