简体   繁体   中英

Slim3 add model to app container

I use SLIM 3 framework, long story short, I have problem with adding Model to the container.

It works fine with the controller:

app.php where I inject Controller and Model

$container['ExampleController'] = function($container){
    return new \App\Controllers\ExampleController($container);
};

$container['ExampleModel'] = function($container){
    return new \App\Models\ExampleModel($container);
};

Then I can use it everywhere when I need to, as long as the container is available:

$this->container->ExampleController->method();

$this->container->ExampleModel->method();

Controller works fine but Model calls fails, here is the error message I get:

Slim\\Exception\\ContainerValueNotFoundException\\nMessage: Identifier "ExampleModel" is not defined

As a note, I don't want to use static models.

Thank you for your time!

我在app.php拼错了 container 谢谢!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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