BispensGipsGebis
BispensGipsGebis

Reputation: 409

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

The RegExConfIrma resides in /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!

Upvotes: 2

Views: 5790

Answers (1)

BispensGipsGebis
BispensGipsGebis

Reputation: 409

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.

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

Upvotes: 6

Related Questions