Home > OS >  Could not load type "App\Form\RepeatedType": class does not exist
Could not load type "App\Form\RepeatedType": class does not exist

Time:05-23

I upgrade from synfony 4 to 5. Then i try to test my registration page and get this: Could not load type "App\Form\RepeatedType": class does not exist.

What i have try:

  • composer install --no-dev --optimize-autoloader (i found this online)

The result:

Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Package operations: 0 installs, 0 updates, 5 removals
  - Removing symfony/web-profiler-bundle (v5.4.8)
  - Removing symfony/maker-bundle (v1.42.0)
  - Removing nikic/php-parser (v4.13.2)
  - Removing doctrine/doctrine-fixtures-bundle (3.4.2)
  - Removing doctrine/data-fixtures (1.5.3)
Generating optimized autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
69 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

Run composer recipes at any time to see the status of your Symfony recipes.

Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 255
!!  Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
!!  Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
!!  Symfony\Component\ErrorHandler\Error\ClassNotFoundError {#83
!!    #message: """
!!      Attempted to load class "MakerBundle" from namespace "Symfony\Bundle\MakerBundle".\n
!!      Did you forget a "use" statement for another namespace?
!!      """
!!    #code: 0
!!    #file: "D:\cours\symfony\blog\vendor\symfony\framework-bundle\Kernel\MicroKernelTrait.php"     
!!    #line: 132
!!    trace: {
!!      D:\cours\symfony\blog\vendor\symfony\framework-bundle\Kernel\MicroKernelTrait.php:132 { …}   
!!      D:\cours\symfony\blog\vendor\symfony\http-kernel\Kernel.php:386 { …}
!!      D:\cours\symfony\blog\vendor\symfony\http-kernel\Kernel.php:786 { …}
!!      D:\cours\symfony\blog\vendor\symfony\http-kernel\Kernel.php:128 { …}
!!      D:\cours\symfony\blog\vendor\symfony\framework-bundle\Console\Application.php:168 { …}       
!!      D:\cours\symfony\blog\vendor\symfony\framework-bundle\Console\Application.php:74 { …}        
!!      D:\cours\symfony\blog\vendor\symfony\console\Application.php:171 { …}
!!      D:\cours\symfony\blog\vendor\symfony\runtime\Runner\Symfony\ConsoleApplicationRunner.php:54 { …}
!!      D:\cours\symfony\blog\vendor\autoload_runtime.php:35 { …}
!!      D:\cours\symfony\blog\bin\console:11 {
!!        ›
!!        › require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
!!        ›
!!        arguments: {
!!          "D:\cours\symfony\blog\vendor\autoload_runtime.php"
!!        }
!!      }
!!    }
!!  }
!!  Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
!!  Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
!!  2022-05-17T00:33:06 02:00 [critical] Uncaught Error: Class 'Symfony\Bundle\MakerBundle\MakerBundle' not found
!!
Script @auto-scripts was called via post-install-cmd 

WEIRD because others forms worked just before (and now they are broken saying: Attempted to load class "MakerBundle" from namespace "Symfony\Bundle\MakerBundle". Did you forget a "use" statement for another namespace?)

  • composer require symfony/maker-bundle --dev Now it's working again except for the registration page ("App\Form\RepeatedType": class does not exist.).

It's worth notting that my autocomplet find Symfony\Component\Form\Extension\Core\Type\RepeatedType in the folder. And sometimes when i clear cache, it crash when optimizing.

Thanks for reading.

CodePudding user response:

In symfony 5 the use statement for RepeatedType is use Symfony\Component\Form\Extension\Core\Type\RepeatedType;

And to use for let's say a password fiel you would type something like:

$builder
->add('password', RepeatedType::class, [
    'type' => PasswordType::class,
    'required' => false,
    'mapped' => false,
    'first_options' => ['label' => 'New password'],
    'second_options' => ['label' => 'Repeat password'],
]);
  • Related