I have this code :
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Blog;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\ORM\Tools\Pagination\Paginator;
class BlogController extends Controller
{
/**
* @Route("/blog", name="blog")
*/
public function index()
{
$entityManager=$this->getDoctrine()->getManager();
$blog = $this->getDoctrine()->getRepository(Blog::class);
$dql = "SELECT id, name FROM Blog";
$query = $entityManager->createQuery($dql)
->setFirstResult(0)
->setMaxResults(100);
$paginator = new Paginator($query, $fetchJoinCollection = true);
$c = count($paginator);
foreach ($paginator as $post) {
echo $post->getHeadline() . "
";
}
return $this->render('blog/index.html.twig', [
'controller_name' => 'BlogController',
'blog' =>$blog,
]);
}
}
But when i run it it gives me
[Semantical Error] line 0, col 22 near 'Blog': Error: Class 'Blog' is not defined. I also tried put
$dql = "SELECT id, name FROM App\Entity\Blog:Blog";
But in this way it gives me
[Syntax Error] line 0, col 37: Error: Expected Doctrine\ORM\Query\Lexer::T_IDENTIFIER, got ':Blog'
I dont know what to do. Please help me