简体   繁体   中英

Controller class not found for Symfony 3 route

I am getting the error

`The _controller value "AppBundle:GasSupplier:overview" maps to a
"AppBundle\Controller\GasSupplierController" class, but this class was not found. Create
this class or check the spelling of the class and its namespace.`

But as far as I can tell, the class does exist, with the correct namespace, in the correct directory. My app/config/routing.yaml is

AppBundle:
    resource: "@AppBundle/Resources/config/routing.yml"

and the contents of my src/AppBundle/Resources/config/routing.yaml is

homepage:
  path: /
  defaults: { _controller: AppBundle:Default:index }

gassupplieroverview:
  path: /gassuppliers
  defaults: { _controller: AppBundle:GasSupplier:overview }

and the contents of my src/AppBundle/Controller/GasSupplier.php is

<?php

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class GasSupplierController extends Controller
{
    public function overviewAction(Request $request)
    {
        $gas_suppliers = $this->getDoctrine()->getEntityManager()->getRepository('AppBundle:GasSupplier')->findAll();

        return $this->render('gas_supplier/overview.html.twig', ['gas_suppliers' => $gas_suppliers]);
    }
}

All the other answers I have found about this, the answer was almost always a typo - I have checked and checked again and I don't think I have any typos...

Using Symfony 3.

Typo: GasSupplierController in the class name, vs GasSupplier.php as the filename.

Wherever it says GasSupplier (including the filename), should be renamed/changed-to GasSupplierController , to match the class name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM