I wanted to implement some services, and the first thing I did was to define the private $em as the EntityManager as follows:
<?php
namespace Users\UsersBundle\Services;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Usuarios\UsersBundle\Entity\User;
/**
* Class UserManager
*/
class UserManager
{
private $em;
/**
* @param EntityManager $em
*/
public function __construct(EntityManager $em)
{
$this->$em = $em;
}
}
An example of a function using the EntityManager inside the very same class:
/**
* Find all posts for a given author
*
* @param User $author
*
* @return array
*/
public function findPosts(User $author)
{
$posts = $this->$em->getRepository('BlogBundle:Post')->findBy(array(
'author' => $author
)
);
return $posts;
}
However when I call any function like for example the one I show above, I get the following error: Catchable Fatal Error: Object of class Doctrine\ORM\EntityManager could not be converted to string.
I did import the service. What am I missing? Thank you in advance for your support.