Reputation: 4233
Trying to do file upload by documentation:
https://symfony.com/doc/current/controller/upload_file.html
I have pasted the code:
// src/Form/ProductType.php
namespace App\Form;
use App\Entity\Product;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\FileType;
class ProductType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// ...
->add('brochure', FileType::class, array('label' => 'Brochure (PDF file)'))
// ...
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Product::class,
));
}
}
And getting error
Class Symfony\Component\Form\AbstractType not found in E:\projektai\php projektai\htdocs\mokomieji\symfony_4_demo\config/services.yaml (which is loaded in resource "E:\projektai\php projektai\htdocs\mokomieji\symfony_4_demo\config/services.yaml").
I see PhpStorm giving warning already that AbstractType is not found. What is wrong here, how to fix?
composer.json:
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"symfony/console": "^4.0",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^4.0",
"symfony/lts": "^4@dev",
"symfony/maker-bundle": "^1.0",
"symfony/orm-pack": "^1.0",
"symfony/twig-bundle": "^4.0",
"symfony/validator": "^4.0",
"symfony/yaml": "^4.0"
},
"require-dev": {
"symfony/dotenv": "^4.0"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-apcu": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"id": "01C1AMZG7RRHZQ87EJYRTRWDDA",
"allow-contrib": false
}
}
}
Upvotes: 1
Views: 2131
Reputation: 904
Did you run composer req form
? Now Symfony4 comes as minimal package. Everything what was built-in in the previous versions, now you have to install via composer. You can do this on two ways. First as before using /package or using alias. Whole list of aliases you can find on symfony.sh.
So if you didn't install forms you can do this using
composer req form
or
composer req symfony/form
Upvotes: 3
Reputation: 12103
Maybe the dependency onto symfony/form
is missing? A quick look at the packages you listed and their dependencies lets me suspect this...
Upvotes: 4