How to Access Services or Config from Inside a Form

The content of this article is no longer relevant because in current Symfony versions, form classes are services by default and you can inject services in them using the service autowiring feature.

現在の Symfony のバージョンでは、フォーム クラスはデフォルトでサービスであり、サービスの自動配線機能を使用してサービスを注入できるため、この記事の内容はもはや関係ありません。

Read the article about creating custom form types to see an example of how to inject the database service into a form type. In the same article you can also read about configuration options for form types, which is another way of passing services to forms.

カスタム フォーム タイプの作成に関する記事を読んで、データベース サービスをフォーム タイプに挿入する方法の例を確認してください。同じ記事で、サービスをフォームに渡す別の方法であるフォーム タイプの構成オプションについても読むことができます。