错误:Slim实例必须是Slim \ Views \ Twig,Slim \ Container给出

时间:2016-06-14 10:28:56

标签: php containers slim-3

我正在Youtube上尝试基本的容器教程,我仍然坚持这一部分。我确保给出了一个twig实例而不是容器,但错误仍然出现。

继承了index.php的容器部分:

<script>
$(document).ready(function(){
   $("#myform").on('submit',function(e){
      e.preventDefault();
      //this will stop default form submit.
   });

   $("#submitButton").on('click',function(e){
      e.preventDefault();
      //your code goes here.
   });
});
</script>

routes.php文件:

$container['view'] = function ($container)
    {
    $view = new \Slim\Views\Twig('src/Views', ['cache' => false,]);
    $view->addExtension(new \Slim\Views\TwigExtension(
    $container->router,
    $container->request->getUri()
    ));

    return $view;
};

$container['loginController'] = function ($container){

    return new \App\Controllers\LoginController($container->view);
};

Controller.php这样:

$app->get('/', 'LoginController:login_redirect');

1 个答案:

答案 0 :(得分:1)

不应该$container['view']作为构造函数参数传递,而不是$container->view?

$container['loginController'] = function ($container){
    return new \App\Controllers\LoginController($container->view);
};