I know the problem is simple, but I can't find how to resolve it. I need to retrieve a value from a variable, but in vain:
I have the following controller:
public function followersAction()
{
$em = $this->getDoctrine()->getManager();
$usr= $this->get('security.context')->getToken()->getUser();
$query = $em->createQuery(
'SELECT p
FROM TESTBlogBundle:Follow p
WHERE p.followed = :me'
)->setParameter('me', $usr->getId());
$followers = $query->getResult();
return array(
'entities' => $followers
);
}
Inside another controller, I am using:
$myfollowers=$this->followersAction();
when I var_dump, I have:
array(3) {
["entities"]=>
array(1) {
[0]=>
object(TEST\Bundle\BlogBundle\Entity\Follow)#364 (3) {
["id":"TEST\Bundle\BlogBundle\Entity\Follow":private]=>
int(1)
["follower"]=>
int(2)
["followed"]=>
int(1)
}
}
["current_user"]=>
int(1)
["followers_count"]=>
int(1)
}
I need to get the value of property :follower.
foreach($myfollowers as $myfollower)
{
echo '<pre>';
var_dump($myfollower[0]->follower);
var_dump($myfollower[0]->getFollower());
var_dump($myfollower->getFollower());
echo '</pre>';
}
I am getting errors like: Trying to get property of non-object, Call to a member function getFollower() on a non-object.
Your help is appreciated.