我正在尝试添加纤细的Flash消息以供我的控制器访问 使用Slim framework 3和Twig,但是出现以下错误:
在null上调用成员函数addMessage(), Buzz \ Controllers \ MailController :: $ flash in C:\ xampp \ htdocs \ myapp \ app \ Controllers \ MailController.php在第63行
// bootfile.php
<?php
$container['MailController'] = function($container){ return new \Buzz\Controllers\MailController($container); };
$container['flash'] = function($container){ return new \Slim\Flash\Messages; };
$container['view'] = function($container){
$twig = new \Slim\Views\Twig(__DIR__ . '/../pages/views', [ 'cache' => false, ]);
$twig->addExtension(new \Slim\Views\TwigExtension( $container->router, $container->request->getUri()));
$view->getEnvironment()->addGlobal('flash', $container->flash);
return $twig;
};
// MailController.php
public function sendmail($request, $response){
$sent = mail->send();
if ($sent) {
$this->flash->addMessage('mailsuccess', 'Thank you for contacting');
}
}