简体   繁体   English

Symfony 2:在控制器中找不到类

[英]Symfony 2: Class not found in Controller

I've been struggling with this for some time now. 我已经为此苦了一段时间了。 It is most likely a rookie/typo problem, but I just can't find it. 这很可能是菜鸟/错字问题,但我只是找不到。

I have this class ... 我有这堂课...

<?php

namespace PriceOrQuality\POQBundle\RegExConf;

use PriceOrQuality\POQBundle\RegExConf\RegExConf;

class RegExConfIrma extends RegExConf {

    public function __construct() {
        $this->start_page = 'https://irma.dk';
        $this->startConnection();
        $this->getAllLinks();
    }

}

?>

that I'm trying to load from this controller. 我正在尝试从此控制器加载。

<?php

// src/PriceOrQuality/POQBundle/Controller/CrawlerController.php;

namespace PriceOrQuality\POQBundle\Controller;

use PriceOrQuality\POQBundle\RegExConf\RegExConfIrma;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Monolog\Logger;
use Monolog\Handler\FirePHPHandler;

Class CrawlerController extends Controller {

    public function testAction($page) {
        if($page == 'irma') {
            $regex = new RegExConfIrma();

            return $this->render('PriceOrQualityBundle:Crawling:crawling_test.html.twig', array('links' => $regex->getLinks()));

        }
    }

}

?>

However I get this error, and I just cannot seem to find the problem. 但是,我收到此错误,并且似乎无法找到问题。

FatalErrorException: Error: Class 'PriceOrQuality\\POQBundle\\RegExConf\\RegExConfIrma' not found in /Users/Rune/Sites/poq/src/PriceOrQuality/POQBundle/Controller/CrawlerController.php line 16 FatalErrorException:错误:在/Users/Rune/Sites/poq/src/PriceOrQuality/POQBundle/Controller/CrawlerController.php第16行中找不到类'PriceOrQuality \\ POQBundle \\ RegExConf \\ RegExConfIrma'

The RegExConfIrma resides in /Users/Rune/Sites/poq/src/PriceOrQuality/POQBundle/RegExConf/RegExConfIrma RegExConfIrma驻留在/ Users / Rune / Sites / poq / src / PriceOrQuality / POQBundle / RegExConf / RegExConfIrma中

I've tried to debug: * the namespace * clearing cache * changing the namespace 我尝试调试:*名称空间*清除缓存*更改名称空间

But nothing helps. 但是没有任何帮助。

Any help is highly appreciated. 非常感谢您的帮助。

Thanks! 谢谢!

The problem was extremely rookie. 问题是新秀。

I forgot to add .php after my file extension as I use Netbeans where the logo showed is as a php file, but without the proper extension. 我忘记在文件扩展名后添加.php,因为我使用的是Netbeans,其中显示的徽标是php文件,但没有正确的扩展名。

So for anyone else finding this post with the same problem: 因此,对于任何其他人发现同样问题的帖子:

  1. Make sure you use the right namespace 确保使用正确的名称空间
  2. Make sure you include or usethe class 确保您包括或使用课程
  3. Make sure of the spelling of the class 确保班级的拼写
  4. Make sure the filename is spelled exactly the same as the class 确保文件名拼写与类完全相同
  5. Make sure you've added .php after the class file 确保在类文件之后添加了.php

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

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