Case mismatch between loaded and declared class names: "Symfony\Bundle\FrameWorkBundle\Controller\Controller" vs "Symfony\Bundle\FrameworkBundle\Controller\Controller".
In my controller i have this:
namespace AppBundle\Controller;
use Symfony\Bundle\FrameWorkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class MainController extends Controller
{
public function homepageAction()
{
return $this->render('main/index.html.twig');
}
}
Maybe just fix what the error tells you? (sorry if that sounds harsh)
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
instead of
use Symfony\Bundle\FrameWorkBundle\Controller\Controller;
Related
I am trying to remove sensio/framework-extra-bundle from composer, however, when I do, I get the error above in my Controllers that have parameterized routes. Not finding the correct answer for a replacement?
Her is an example controller snippet.
namespace App\Controller;
use App\Entity\Ticket;
use App\Form\TicketType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/admin/ticket')]
class TicketController extends AbstractController
{
#[Route('/{id}', name: 'app_ticket_show', methods: ['GET'])]
public function show(Ticket $ticket): Response
{
return $this->render('ticket/show.html.twig', [
'ticket' => $ticket,
]);
}
}
I was working on my first project with Symfony, I created my first controller. And this error appears.
problem image
I tried to
composer update
and I got the same problem!
The problem that appear when i update the composer
here is the code of TestController.php
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class TestController extends Controller {
/**
* #Route("/")
* #Method ({"GET"})
*/
public function index()
{
//return new Response('<html><body>Hello world</body></html>');
return $this->render('articles/index.html.twig');
}
}
index.html.twig file has only a <h1> test </h1> on it
What makes that problem appear? and how to fix it without deleting the project and creating it again!
thanks
Symfony\Bundle\FrameworkBundle\Controller\Controller has been deprecated since v4.2.0 and removed since v5.0.0, use Symfony\Bundle\FrameworkBundle\Controller\AbstractController instead.
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class TestController extends AbstractController {
/**
* #Route("/", methods={"GET"})
*/
public function index()
{
//return new Response('<html><body>Hello world</body></html>');
return $this->render('articles/index.html.twig');
}
}
I am calling repository function with following detail
$ratingData = $em->getRepository(PatientFeedback::class)->getRatingReviewData($doctorId, $this->timezone);
and my repository class is like:
namespace App\Repository;
class PatientFeedbackRepository extends ServiceEntityRepository
{
}
getting error like:
Attempted to call function \"getRatingReviewData\" from namespace \"Api\\Controller\".
is anything specific I am missing to use entity repository?
You have a syntax error:
$em->getRepository(PatientFeedback::class)>getRatingReviewData(...)
to:
$em->getRepository(PatientFeedback::class)->getRatingReviewData(...)
Without the -, it's looking for a function nammed getRatingReviewData in the current namespace
Use EntityRepository instead of ServiceEntityRepository :
use Doctrine\ORM\EntityRepository;
class UsersRepository extends EntityRepository
I am using Symfony 3.4 and when I'm trying to run server there is an error:
In RegisterControllerArgumentLocatorsPass.php line 68:
Class "AppBundle\Controller\HomeController" used for service "AppBundle\Controller\HomeController" cannot be found.
How can I deal with this problem?
The same error manifests when a controller extends Symfony's AbstractController and does not import it.
Solved by adding the import to the controller:
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class HomeController extends Controller
{
/**
* #Route('/')
* #return \Symfony\Component\HttpFoundation\Response
*/
public function indexAction()
{
return $this->render('home/index.html.twig');
}
}
Exception thrown when handling an exception (Symfony\Component\Config\Exception\FileLoaderLoadException: [Syntax Error] Expected PlainValue, got ''' at position 7 in method AppBundle\Controller\HomeController::indexAction() in /home/remas/relevium_symfony/src/AppBundle/Controller/ (which is being imported from "/home/remas/relevium_symfony/app/config/routing.yml"). Make sure annotations are installed and enabled.)
I am using Symfony 3.4.3.
This is my routing in
app/config/routing.yml:
blog:
resource: "#BlogBundle/Controller/"
type: annotation
this is my controller from BlogBundle/Controller/DefaultController.php
<?php
namespace BlogBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
/**
* #Route("/home", name="home_route")
*/
class DefaultController extends Controller
{
public function indexAction()
{
return $this->render('BlogBundle:Default:index.html.twig');
}
}
And when I go to http://localhost:8000/home address I am getting this error: No route found for "GET /home"
So, what am I doing wrong here?
You add to set the route annotation on the action
<?php
namespace BlogBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller
{
/**
* #Route("/home", name="home_route")
*/
public function indexAction()
{
return $this->render('BlogBundle:Default:index.html.twig');
}
}
If you use annotation on the class, is to prefix all actions