Service Manager で Zend 3 のドキュメントを読んでいたところ、この問題が発生しました。
ドキュメントでは、コントローラーに DI がある場合は、module.config.php
ファイルを更新してコントローラー キーを追加しInvokableFactory::class
、カスタム ファクトリ クラスではなくコントローラーを呼び出して、最初のコントローラーが使用するクラスの配列を含む別のキー service_manager を追加する必要があると記載されています。
わかりましたので、私はそれをします:
module.config.php
'service_manager' => [
'factories' => [
Controller\Controller2::class => Factory\Controller2Factory::class,
Controller\Controller3::class => Factory\Controller3Factory::class,
],
],
'controllers' => [
'factories' => [
Controller\Controller1::class => Factory\Controller1Factory::class
],
]
Controller1Factory.php
class Controller1Factory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new Controller1(
$container->get(Controller2::class),
$container->get(Controller3::class),
);
}
}
しかし、Controller2 と Controller3 のコンストラクターにも DI があるというエラーが発生したため、モデルに到達するまで、新しいカスタム ファクトリなどを作成します。
また、モデルには、zend ネイティブであるコントローラーに注入される依存関係もあり\Zend\Db\TableGateway\TableGatewayInterface
、conf ファイルを再度編集して追加する必要がありますTableGatewayInterface
。
そして、それは間違っています。この方法でネイティブの zend クラスとサービスを注入することを強制されるべきではありません。
それで、私は何を間違っていますか?