我想添加带有安全上下文的表单服务,如下所示:
namespace Infogold\AccountBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Doctrine\ORM\EntityRepository;
class KonsultantType extends AbstractType {
protected $user;
public function __construct(SecurityContext $user) {
$this->user = $user;
}
public function buildForm(FormBuilderInterface $builder, array $options) {
-
-
-
-
-
-
public function getName() {
return 'konsultanci_form';
}
在服务中:
parameters:
# infogold_account.example.class: Infogold\AccountBundle\Example
services:
form.type.konsultanci_form:
class: Infogold\AccountBundle\Form\KonsulantType
arguments: ['@security.context']
tags:
- { name: form.type, alias: konsultanci_form }
我收到了这个错误:
FatalErrorException:错误:在D:\ xampp \ htdocs \ symfony4 \ app \ cache \ dev \ appDevDebugProjectContainer.php第718行找不到类'Infogold \ AccountBundle \ Form \ KonsulantType'
718行是:
protected function getForm_Type_KonsultanciFormService()
{
return $this->services['form.type.konsultanci_form'] = new \Infogold\AccountBundle\Form\KonsulantType($this->get('security.context'));
}
我犯了错误?
答案 0 :(得分:1)
正如我所说,这是班级名称的错误。它是KonsultantType
而不是KonsulantType
尝试:
parameters:
# infogold_account.example.class: Infogold\AccountBundle\Example
services:
form.type.konsultanci_form:
class: Infogold\AccountBundle\Form\KonsultantType
arguments: ['@security.context']
tags:
- { name: form.type, alias: konsultanci_form }