简体   繁体   English

找不到Symfony 3路由的控制器类

[英]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 我的app / config / routing.yaml是

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

and the contents of my src/AppBundle/Resources/config/routing.yaml is 并且我的src / AppBundle / Resources / config / routing.yaml的内容是

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 并且我的src / AppBundle / Controller / GasSupplier.php的内容是

<?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. 使用Symfony 3。

Typo: GasSupplierController in the class name, vs GasSupplier.php as the filename. 错别字:类名称中为GasSupplierController,而文件名则为GasSupplier.php。

Wherever it says GasSupplier (including the filename), should be renamed/changed-to GasSupplierController , to match the class name. 无论GasSupplier (包括文件名)在哪里显示,都应重命名/更改为GasSupplierController ,以匹配类名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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