PhpStorm Symfony 4 ContactType类无法识别 [英] PhpStorm Symfony 4 ContactType class not recognized
问题描述
我今天有一个很烦人的问题.我使用的是Macbook Pro,PhpStorm 2017.3.6.
I have a very annoying problem today. I'm on Macbook Pro, PhpStorm 2017.3.6.
我试图创建一个简单的Symfony 4联系人表单,但PhpStorm出了点问题,根本无法识别联系人类型"类.我已经尝试过:
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:
- 清除PhpStorm缓存并使之失效
- 清除Symfony缓存
- 重新启动Macbook
- 将PhpStorm更新为2017.3.6
我还尝试用其他名称创建formType,例如TotoType
,并且它可以正常工作,因此只有ContactType
不能正常工作.
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.
我也使用git,所以也许是某个地方的缓存"问题或与PhpStorm相关的问题?
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,
]);
}
}
我还注意到,PhpStorm像这样的屏幕快照突出显示了有关我的Kernel.php
文件的一些错误,而且我不知道是否相关:
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:
Kernel.php文件:
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');
}
}
推荐答案
我还尝试使用其他名称创建formType,例如
TotoType
,并且它可以正常工作,因此只有ContactType
不能正常工作.
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.
基于屏幕截图...整个ContactType.php
文件都被视为纯文本..因此,难怪IDE无法识别该类.
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
- 在顶部列表中找到
Text
文件类型条目 - 在底部列表中找到并删除违规模式-将为
ContactType.php
或非常相似.
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.
我还注意到,PhpStorm像这样的屏幕快照突出显示了有关我的
Kernel.php
文件的一些错误,而且我不知道是否相关:
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.
这篇关于PhpStorm Symfony 4 ContactType类无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!