问题
I have a very annoying problem today. I'm on Macbook Pro, PhpStorm 2017.3.6.
I tried to create a simple Symfony 4 contact form but something goes wrong with PhpStorm, the class "Contact Type" isn't recognized at all. I already tried to:
- Clear and invalidate PhpStorm cache
- Clear Symfony cache
- Reboot the Macbook
- Updated PhpStorm to 2017.3.6
I also tried to create the formType with another names, like TotoType
for example and it's working, so its only with ContactType
that's not working.
I use git also, so maybe it's a "cache" problem somewhere or a PhpStorm related problem?
<?php
namespace App\Form;
use App\Entity\Contact;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ContactType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('field_name')
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// uncomment if you want to bind to a class
//'data_class' => Contact::class,
]);
}
}
I also noticed that PhpStorm highlighted few errors about my Kernel.php
file like this screenshot, and I don't know if things are related or not:
The Kernel.php file:
<?php
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function getCacheDir()
{
return $this->getProjectDir().'/var/cache/'.$this->environment;
}
public function getLogDir()
{
return $this->getProjectDir().'/var/log';
}
public function registerBundles()
{
$contents = require $this->getProjectDir().'/config/bundles.php';
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
}
}
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
{
$container->setParameter('container.autowiring.strict_mode', true);
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir().'/config';
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
}
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$confDir = $this->getProjectDir().'/config';
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
}
}
回答1:
I also tried to create the formType with another names, like
TotoType
for example and it's working, so its only withContactType
that's not working.
Based on screenshot ... the whole ContactType.php
file is treated as plain text .. so no wonders that IDE does not recognize that class.
You must have accidentally marked this file as Text. To undo:
Settings/Preferences | File Types
- Locate
Text
file type entry in the top list - Locate and remove offending pattern in the bottom list -- it will be
ContactType.php
or pretty similar.
I also noticed that PhpStorm highlighted few errors about my
Kernel.php
file like this screenshot, and I don't know if things are related or not:
Not related to the first issue for sure -- must be something else.
来源:https://stackoverflow.com/questions/49439691/phpstorm-symfony-4-contacttype-class-not-recognized