【问题标题】:Slim3 add model to app containerSlim3 将模型添加到应用容器
【发布时间】:2016-10-14 12:06:27
【问题描述】:

我使用 SLIM 3 框架,长话短说,我在将模型添加到容器时遇到问题。

它与控制器配合得很好:

app.php 我在其中注入 Controller 和 Model

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

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

然后我可以在需要时在任何地方使用它,只要容器可用:

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

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

控制器工作正常,但模型调用失败,这是我得到的错误消息:

Slim\Exception\ContainerValueNotFoundException\n消息:未定义标识符“ExampleModel”

请注意,我不想使用静态模型。

感谢您的宝贵时间!

【问题讨论】:

  • 可能是错字...
  • 没有理由这不起作用。虽然没有看到你从哪里得到 $this->container 是唯一有问题的东西
  • 你们是对的人,我在 app.php 中拼错了容器,我检查了 100 次...感谢您的帮助!

标签: php slim


【解决方案1】:

我在app.php 中拼错了容器,谢谢!

【讨论】:

    猜你喜欢
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 2020-04-19
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多