PhpStorm Symfony 4 ContactType class 无法识别
PhpStorm Symfony 4 ContactType class not recognized
今天有个很烦人的问题。我在 Macbook Pro,PhpStorm 2017.3.6.
我试图创建一个简单的 Symfony 4 联系表单,但 PhpStorm 出了点问题,class "Contact Type" 根本无法识别。我已经尝试过:
- 清除并使 PhpStorm 缓存失效
- 清除 Symfony 缓存
- 重启 Macbook
- 已将 PhpStorm 更新至 2017.3.6
我还尝试用其他名称创建 formType,例如 TotoType
,它正在工作,所以只有 ContactType
才不起作用。
我也使用 git,所以可能是某个地方的 "cache" 问题或与 PhpStorm 相关的问题?
<?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
文件的一些错误,我不知道是否相关:
Kernel.php 文件:
<?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');
}
}
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.
根据屏幕截图...整个 ContactType.php
文件被视为纯文本.. 所以难怪 IDE 无法识别 class.
您一定是不小心将此文件标记为文本。撤消:
Settings/Preferences | File Types
- 在顶部列表中找到
Text
文件类型条目
- 在底部列表中找到并删除违规模式 -- 它将是
ContactType.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:
肯定与第一个问题无关 -- 一定是其他问题。
今天有个很烦人的问题。我在 Macbook Pro,PhpStorm 2017.3.6.
我试图创建一个简单的 Symfony 4 联系表单,但 PhpStorm 出了点问题,class "Contact Type" 根本无法识别。我已经尝试过:
- 清除并使 PhpStorm 缓存失效
- 清除 Symfony 缓存
- 重启 Macbook
- 已将 PhpStorm 更新至 2017.3.6
我还尝试用其他名称创建 formType,例如 TotoType
,它正在工作,所以只有 ContactType
才不起作用。
我也使用 git,所以可能是某个地方的 "cache" 问题或与 PhpStorm 相关的问题?
<?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
文件的一些错误,我不知道是否相关:
Kernel.php 文件:
<?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');
}
}
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 无法识别 class.
您一定是不小心将此文件标记为文本。撤消:
Settings/Preferences | File Types
- 在顶部列表中找到
Text
文件类型条目 - 在底部列表中找到并删除违规模式 -- 它将是
ContactType.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:
肯定与第一个问题无关 -- 一定是其他问题。