Error: Slim instance must be Slim\Views\Twig, Slim\Container given
Error: Slim instance must be Slim\Views\Twig, Slim\Container given
我正在尝试 Youtube 上的基本容器教程,但我卡在了这部分。我确定给出的是树枝实例而不是容器,但错误仍然出现。
这里是 index.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);
};
routes.php:
$app->get('/', 'LoginController:login_redirect');
controller.php:
use Slim\Views\Twig as View;
protected $view;
public function __construct(View $view){
$this->view = $view;
}
public function login_redirect($request, $response){
$this->view->render($response, 'testing.twig');
}
不应将 $container['view']
作为构造函数参数传递给此处,而不是 $container->view?
$container['loginController'] = function ($container){
return new \App\Controllers\LoginController($container->view);
};
我正在尝试 Youtube 上的基本容器教程,但我卡在了这部分。我确定给出的是树枝实例而不是容器,但错误仍然出现。
这里是 index.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);
};
routes.php:
$app->get('/', 'LoginController:login_redirect');
controller.php:
use Slim\Views\Twig as View;
protected $view;
public function __construct(View $view){
$this->view = $view;
}
public function login_redirect($request, $response){
$this->view->render($response, 'testing.twig');
}
不应将 $container['view']
作为构造函数参数传递给此处,而不是 $container->view?
$container['loginController'] = function ($container){
return new \App\Controllers\LoginController($container->view);
};