I need to get there some more data and for some other pages I need also db inserts etc…
My standard code is:
namespace App\Controllers;
use Slim\Views\Twig;
use Psr\Log\LoggerInterface;
use Illuminate\Database\Query\Builder;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
class SitecheckController
{
private $view;
private $logger;
protected $table;
public function index(Request $request, Response $response, $args)
{
//return "contr. return msg!";
return $this->view->render($response, 'home.twig');
}
}
I tried to do copy and rename this controller from github, but I get now this error: Argument 1 passed to App\Controllers\SitecheckController::__construct() must be an instance of Slim\Views\Twig
My construct class is:
private $view;
private $router;
private $flash;
public function __construct(Twig $view, Router $router, FlashMessages $flash)
{
$this->view = $view;
$this->router = $router;
$this->flash = $flash;
}
Hello! I don’t understand how to use twig render outside the response psr7 …
If in my controller I use a private function to send an email, I can’t use
$this->view->render('email/template.twig');
because slim return
Argument 1 passed to Slim\Views\Twig::render() must implement interface Psr\Http\Message\ResponseInterface, string given …
I used and followed the bookshelf example, infact everything else is ok.
What is the best practice to send htmlbody email rendered by twig in a separate controller function ?
For a single function as sendEmail() I must pass the $response object from dispatch funcion? It’s correct to think in this way ?
Thank you very very much!
Thank you @tflight ! Thanks for your help !
It works now without load another Twig in my DI :)) I was making a mess
Now I also discovered fetchFromString