array(3) {
["db"]=>
array(3) {
["dsn"]=>
string(63) "mysql:host=sv62.star.ne.jp:3306;dbname=webap_db;charset=utf8mb4"
["user"]=>
string(10) "webap_user"
["pass"]=>
string(10) "webap_pass"
}
["twig"]=>
array(2) {
["template"]=>
string(30) "/home/webap/logdb.net/app/View"
["options"]=>
array(3) {
["debug"]=>
bool(true)
["strict_variables"]=>
bool(true)
["cache"]=>
bool(false)
}
}
["logger"]=>
array(3) {
["level"]=>
string(5) "DEBUG"
["name"]=>
string(9) "logdb-app"
["path"]=>
string(46) "/home/webap/logdb.net/app/../log/logdb-app.log"
}
}
Warning: Attempt to read property "request" on array in /home/webap/logdb.net/app/Controller/ControllerAbstract.php on line 34
NULL
array(18) {
["Accept-Language"]=>
array(1) {
[0]=>
string(14) "en-US,en;q=0.5"
}
["Accept"]=>
array(1) {
[0]=>
string(63) "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
}
["User-Agent"]=>
array(1) {
[0]=>
string(40) "CCBot/2.0 (https://commoncrawl.org/faq/)"
}
["Connection"]=>
array(1) {
[0]=>
string(5) "close"
}
["X-File-Type"]=>
array(1) {
[0]=>
string(6) "normal"
}
["X-Ua-Device"]=>
array(1) {
[0]=>
string(2) "pc"
}
["X-Failure-Cache-Time"]=>
array(1) {
[0]=>
string(1) "0"
}
["X-Accel-Expires"]=>
array(1) {
[0]=>
string(2) "60"
}
["X-Wp-Access"]=>
array(1) {
[0]=>
string(1) "0"
}
["X-Php-Fpm-Version"]=>
array(1) {
[0]=>
string(2) "83"
}
["X-Server-Address"]=>
array(1) {
[0]=>
string(14) "157.112.187.83"
}
["X-Real-Ip"]=>
array(1) {
[0]=>
string(14) "34.231.180.210"
}
["X-Forwarded-Ssl"]=>
array(1) {
[0]=>
string(2) "on"
}
["X-Forwarded-Port"]=>
array(1) {
[0]=>
string(3) "443"
}
["X-Forwarded-Host"]=>
array(1) {
[0]=>
string(9) "logdb.net"
}
["X-Forwarded-Proto"]=>
array(1) {
[0]=>
string(5) "https"
}
["X-Forwarded-For"]=>
array(1) {
[0]=>
string(14) "34.231.180.210"
}
["Host"]=>
array(1) {
[0]=>
string(9) "logdb.net"
}
}
The Twig-View PHP component helps you render Twig templates in your application. This component is available on Packagist, and it’s easy to install with Composer like this:
composer require slim/twig-view
Next, you need to add the middleware to the Slim app:
Note: For production scenarios, cache
should be set to some
'path/to/cache'
to store compiled templates (thus avoiding recompilation on every request).
For more information, see Twig environment options
$app->get('/', function ($request, $response) {
$view = Twig::fromRequest($request);
return $view->render($response, 'home.html.twig', [
'name' => 'John',
]);
});
// Run app
$app->run();
In this example, $view
invoked inside the route callback is a reference to the \Slim\Views\Twig
instance returned by the fromRequest
method.
The \Slim\Views\Twig
instance’s render()
method accepts a PSR-7 Response object as its first argument, the Twig template path as its second argument, and an array of template variables as its final argument.
The render()
method returns a new PSR-7 Response object whose body is the rendered Twig template.
Create a directory in your project root: templates/
Create a Twig template file within the templates directory: templates/home.html.twig
<!DOCTYPE html>
<html>
<head>
<title>Welcome to Slim!</title>
</head>
<body>
<h1>Hello test</h1>
</body>
</html>