$this in that context appears to be the TestController class which likely doesn’t have a get method. You are likely confusing it with a container instance.
namespace App\Controllers;
use App\Exceptions\NotFoundHttpException;
use PDO;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Exception\HttpNotFoundException;
use Slim\Views\Twig;
class TestController{
protected $view;
protected $db;
public function __construct(Twig $view, $db){
$this->view = $view;
$this->db = $db;
}
public function register(Request $request, Response $response, $args){
$data = $request->getParsedBody();
// DB Insert
$this->get('flash')->addMessage('registered', true);
//...
}
}
In that context, $this is referring to your TestController instance. You will want to bring your instance of Flash into your controller just like you are bringing in your view and the $db. Then you can refer to it as $this->flash->addMessage(...) instead of $this->get(…)`. Something like this (untested).
namespace App\Controllers;
use App\Exceptions\NotFoundHttpException;
use PDO;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Exception\HttpNotFoundException;
use Slim\Flash\Messages as Flash;
use Slim\Views\Twig;
class TestController{
protected $view;
protected $db;
protected $flash;
public function __construct(Twig $view, $db, Flash flash$){
$this->view = $view;
$this->db = $db;
$this->flash = $flash;
}
public function register(Request $request, Response $response, $args){
$data = $request->getParsedBody();
// DB Insert
$this->flash->addMessage('registered', true);
//...
}
}