我想添加具有安全上下文的表单服务如下:
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: Error: Class 'Infogold''AccountBundle''Form''KonsulantType' 在 D:''xampp''htdocs''symfony4''app''cache''dev''appDevDebugProjectContainer.php 行 718 中找不到
718线是:
protected function getForm_Type_KonsultanciFormService()
{
return $this->services['form.type.konsultanci_form'] = new 'Infogold'AccountBundle'Form'KonsulantType($this->get('security.context'));
}
我哪里犯了错误?
正如我所说,这是类名上的错误。它是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 }