执行createForm
方法时出错。
InvalidArgumentException: Could not load type "ArticleType"
我的 symfony 版本是3.3.*
.
我尝试使用而不是执行该createForm
方法。Article::class
ArticleType::class
这是我的代码,问题出在哪里?
文章控制器.php
public function createAction(Request $request)
{
$article = new Article();
$form = $this->createForm(ArticleType::class, $article);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// ...
}
return $this->render('admin/article/create.html.twig', [
'form' => $form->createView()
]);
}
文章类型.php
class ArticleType extends AbstractType
{
private $categoryService;
private $tagService;
public function __construct(CategoryService $categoryService, TagService $tagService)
{
$this->categoryService = $categoryService;
$this->tagService = $tagService;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/.
public function buildForm(FormBuilderInterface $builder, array $options)
{
// ...
}
public function setDefaultOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => 'CMS\Bundle\ContentBundle\Entity\Article'
]);
}
}
Resources/config/services.yml(包含在 app/config/services.yml 中)
services:
CMS\Bundle\ContentBundle\Form\ArticleType:
arguments: ['@cms.core.service.category', '@cms.core.service.tag']
tags: [form.type]
.