__contruct中的symfony 4 autowire关注

时间:2019-02-07 16:50:40

标签: symfony

这是我在Symfony 4中非常简单的课程:

      .mdc-select__label {
        left: 0;
        right: initial;
        position: absolute;
        bottom: 8px;
        left: 0;
        -webkit-transform-origin: left top;
        transform-origin: left top;
        -webkit-transition: -webkit-transform 180ms cubic-bezier(0.4, 0, 0.2, 1);
        transition: -webkit-transform 180ms cubic-bezier(0.4, 0, 0.2, 1);
        transition: transform 180ms cubic-bezier(0.4, 0, 0.2, 1);
        transition: transform 180ms cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 180ms cubic-bezier(0.4, 0, 0.2, 1);
        pointer-events: none;
        will-change: transform;
      }

      [dir="rtl"] .mdc-select__label,
      .mdc-select__label[dir="rtl"] {
        left: initial;
        right: 0;
      }

      .mdc-select[dir="rtl"] .mdc-select__label,
      [dir="rtl"] .mdc-select .mdc-select__label {
        -webkit-transform-origin: right top;
        transform-origin: right top;
      }

      .mdc-select__label--float-above {
        -webkit-transform: translateY(-100%) scale(0.75);
        transform: translateY(-100%) scale(0.75);
      }


<div id="root" class\$="mdc-select mdc-select--box mdc-menu-anchor [[addClass]]" role="listbox">
      <div id="surface" class\$="mdc-select__surface [[_error(error)]]" tabindex="0">
        <div id="label" class\$="mdc-select__label [[_float(value)]] [[_hide(label)]]">[[label]]</div>
        <div class="mdc-select__selected-text">[[_display(value)]]</div>
        <div class="mdc-select__bottom-line hidden"></div>
      </div>
      <div id="menu" class\$="mdc-menu mdc-select__menu [[addMenuClass]]">
        <ul class="mdc-list mdc-menu__items" on-click="_selectItem">
          <template is="dom-repeat" id="items" items="[[items]]" mutable-data>
            <li class="mdc-list-item" role="option" tabindex="0">[[_display(item)]]</li>
          </template>
        </ul>
      </div>
      <i id="clear" class$="material-icons mdc-text-field__icon [[_showIfClearable(clearable)]]" on-click="clear">clear</i>
</div>

但是我总是得到: 无法自动装配服务“ App \ Controller \ T_contact”:方​​法“ __construct()”的参数“ $ email” 没有类型提示,您应显式配置其值。

我尝试过: “ ...__ construct(字符串$ email,字符串$ name)” 但我得到几乎相同的消息,除了: “ ... 是带有类型提示的”字符串“ ,您应该配置...

我不明白。 任何线索欢迎...

1 个答案:

答案 0 :(得分:0)

由于Symfony不知道要插入哪个字符串,因此无法自动装配字符串。服务通过它们的用作标识符的类或接口自动连接,但是带有参数(int,字符串和数组),Symfony无法猜测要注入的参数。这就是为什么您收到错误消息...you should configure its value explicitly.

的原因

因此,您需要在services.yml中手动指定它们

示例:

  App/Controller/T_contact:
      arguments:
          $email: 'your_email'
          $name: 'your_name'  

补充说明:最佳做法是CamelCase您的类名,如果它是控制器,则在其后缀术语Controller(即TContactController)