したがって、次のように Pimple との依存関係を追加したコントローラーがあります。
$this->container['Account'] = $this->container->factory(function ($c) {
return new Account(
$c['Menu_builder']
);
});
そして、このコントローラーのアクションの URL に移動すると、次のように表示されます。
Message: Argument 1 passed to Account::__construct() must be an instance of Menu_builder, none given, called in website/system/core/CodeIgniter.php on line 482 and defined Filename: controllers/Account.php Line Number: 13
依存関係のあるクラスをロードするには、通常次のように言います。
$account = $this->container['Account'];
しかし、フレームワークコントローラーの場合、この呼び出しをどこに置くべきかわかりません。
コントローラーは次のようになります。
class Account extends MY_Controller
{
private $menu_builder;
public function __construct(Menu_builder $menu_builder){
$this->menu_builder = $menu_builder;
}
// ...
}
質問: ここで何が間違っていますか? 上記は、コントローラー以外のクラスを返す場合に正常に機能します。