Reputation:
This is with Symfony2 and Doctrine2. I have this in my user entity:
public function getRoles()
{
return $this->roles->toArray();
}
Yet however, it is returning:
array(object(Role))
Any ideas where I can start looking? I've been debugging for a while.
Upvotes: 1
Views: 3371
Reputation: 608
I bumped into this error myself after following the Cookbook Tutorial on Loading Users From Database, and maybe this is your case.
It turns out I forgot to implement the RoleInterface
on my Role
entity object (the one referenced by my User
entity). That was it.
Upvotes: 1
Reputation: 6137
This is the logical behavior ; by default, Doctrine2 returns a Collection
object, and by calling toArray()
you transform it into an array. But your array still contains Role
objects, that are basically not strings. Of course, you can define your own methods to get it as a string, I think basically you just have to call Role::getRole()
.
Have a look at this article, it may help you.
Upvotes: 2