symfony: Error: Call to a member function getDateTime() on a non-object
<p>How can I solve </p>

<blockquote>
  <p><code>Error: Call to a member function getDateTime() on a non-object</code></p>
</blockquote>

<p>Here are is my code:</p>

<pre><code>  $repository = $this-&gt;getDoctrine()
        -&gt;getRepository('AppBundle\Entity\Menu');
        $today = date_create_from_format('Y-m-d H:i', date('Y-m-d H:i'));

        $menu = $repository-&gt;findAll();

        if($menu-&gt;getDateTime() == \DateTime('now')){
            $primiOne = $menu-&gt;getPrimiOne();
            $primiTwo = $menu-&gt;getPrimiTwo();
            $primiThree = $menu-&gt;getPrimiThree();
            $secondOne = $menu-&gt;getSecondOne();
            $secondTwo = $menu-&gt;getSecondTwo();
            $secondThree = $menu-&gt;getSecondThree();
            $sideOne = $menu-&gt;getSideOne();
            $sideTwo = $menu-&gt;getSideTwo();
            $sideThree = $menu-&gt;getSideThree();
</code></pre>

<p>and the entity is:</p>

<pre><code> /**
 * @var \DateTime
 *
 * @ORM\Column(name="date_time", type="string")
 */
private $dateTime;
/**
 * Set dateTime
 *
 * @param string $dateTime
 *
 * @return Menu
 */
public function setDateTime($dateTime)
{
    $this-&gt;dateTime = $dateTime;

    return $this;
}

/**
 * Get dateTime
 *
 * @return string
 */
public function getDateTime()
{
    return $this-&gt;dateTime;
}
</code></pre>