PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 16, 2022

[FIXED] Symfony 4 : The file was found but the class was not in it

 January 16, 2022     autoloader, composer-php, routes, symfony, symfony4     No comments   

Issue

this problem has been asked a lot but none of the answer could help me. I'm doing a symfony 4 upgrade of an outdated symfony 3. I removed all the bundle to have to correct file architecture but i probably messed something up.

Just doing bin/console in the command line I get this error :

The autoloader expected class "App\Controller\BrandAcadamyFeedback\FeedbackAnswerController" to be defined in file "/Users/username/www/myfolder/sf/vendor/composer/../../src/Controller/BrandAcadamyFeedback/FeedbackAnswerController.php". The file was found but the class was not in it, the class name or namespace probably has a typo in /Users/username/www/myfolder/sf/config/services.yaml (which is loaded in resource "/Users/username/www/myfolder/sf/config/services.yaml").

Here are my files :

Services.yaml

imports:
- { resource: security.yaml }

parameters:
   locale: 'en'

services:
    _defaults:
        autowire: true      
        autoconfigure: true 
        public: false

    App\:
        resource: '../src/*'
        exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'

    App\Controller\:
        resource: '../src/Controller/*'
        tags: ['controller.service_arguments']

FeedbackAnswerController.php

namespace App\Controller\BrandAcadamyFeedback;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\ConstraintViolationList;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\Routing\Annotation\Route;
use FOS\RestBundle\Controller\Annotations\View;
use FOS\RestBundle\Controller\Annotations\Post;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use App\Controller\API\APIController;

/**
* Controller for Entity\BrandAcadamyFeedback\FeedbackAnswer.
*
* @View
* @Route("/api/feedback-answer")
*/
class FeedbackAnswerController extends APIController
{
}

Annotations.yaml

controllers:
    resource: ../../src/Controller/
    type: annotation

Composer.json

"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
}

It's probably something easy but couldn't figure it out, nor find an answer online.

Any help would be highly appreciated. I hope I gave enough information.


Solution

Thanks to Cerad comment I went and quadruple check the namespace for my controllers and there was indeed an error spell in the folder name of my app.

"App\Controller\BrandAcadamyFeedback\" should have been App\Controller\BrandAcademyFeedback\

Sorry.



Answered By - Alexandre Olive
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing