简体   繁体   English

Symfony3中的__construct()和service.yml

[英]__construct() and service.yml in Symfony3

I have some issues with my code, it has separate form, controller and service. 我的代码有一些问题,它具有单独的形式,控制器和服务。 Where is the issue here? 这里的问题在哪里?

form: https://pastebin.com/ERU6hChv controller: https://pastebin.com/FMzJ493v service: 形式: https : //pastebin.com/ERU6hChv控制器: https : //pastebin.com/FMzJ493v服务:

# app/config/services.yml
services:
    app.form.type.przydzial:
        class: AppBundle\Form\PrzydzialType
        arguments: ['@session']
        tags:
            - { name: form.type }

unfortunately i have a warrning: 不幸的是我有一个警告:

"Warning: Missing argument 1 for AppBundle\Form\PrzydzialType::__construct(), called in G:\Xampp\htdocs\projects\godziny_inz\vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php on line 85 and defined"

Stack Trace: 堆栈跟踪:

"in src\AppBundle\Form\PrzydzialType.php at line 64"

return 'appbundle_przydzial';
}

public function __construct($session)
{
$this->session = $session; <----------64 line

EDIT: 编辑:

if i change this line: 
$form = $this->createForm('AppBundle\Form\PrzydzialType', $przydzial);
to 
$form = $this->createForm('app.form.type.przydzial', $przydzial);

I have different warning: 我有不同的警告:

Could not load type "app.form.type.przydzial" 无法加载类型“ app.form.type.przydzial”

Stack Trace: 堆栈跟踪:

in vendor\\symfony\\symfony\\src\\Symfony\\Component\\Form\\FormRegistry.php at line 87 在第87行的vendor \\ symfony \\ symfony \\ src \\ Symfony \\ Component \\ Form \\ FormRegistry.php中

if (class_exists($name) && in_array('Symfony\Component\Form\FormTypeInterface', class_implements($name))) {
$type = new $name();
} else {
throw new InvalidArgumentException(sprintf('Could not load type "%s"', $name)); <---line 87
}
}

It looks like your Form Type is created with new in the FormRegistry instead of using your service. 看起来您的表单类型是使用FormRegistry中的new创建的,而不是使用您的服务。 You can find the exact location where this happens in the FormRegistry . 您可以在FormRegistry中找到发生这种情况的确切位置。 Since you created a service and tagged it as form.type I can only assume the problem is somewhere inside the AppBundle\\Form\\PrzydzialType class. 由于您创建了服务并将其标记为form.type所以我只能假设问题出在AppBundle\\Form\\PrzydzialType类中。

Most likely you either forgot to extend Symfony\\Component\\Form\\AbstractType or accidentally extended from a wrong one (check your use statements). 您很可能忘记了扩展Symfony\\Component\\Form\\AbstractType或意外地从错误的扩展名(请检查您的use语句)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM