FatalErrorException: Error: Call to a member function getId() on a non-object in /home/project/src/Sample/MainBundle/Controller/SampleLogController.php line 19
I am using Symfony v.2.3 and I kept getting this error today.
Here is my controller:
public function NewAction(Request $request){
$user = $this->getUser()->getId();
//var_dump($user);
$repository = $this->getDoctrine()
->getRepository('SampleMainBundle:SampleLog');
$sample_repository = $repository->findByUser($user);
//...
}
MyEntities:
class SampleLog
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var integer
*
* @ORM\Column(name="user", type="integer")
*/
protected $user;
//...
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* Get userid
*
* @return integer
*/
public function getUser()
{
return $this->user;
}
//...
}