add example codes.

This commit is contained in:
Hiroaki Matsuura
2017-01-11 11:03:38 +09:00
parent 63dac28733
commit 7c234615e4
5 changed files with 50 additions and 0 deletions

1
example/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/vendor

2
example/cache/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

6
example/composer.json Normal file
View File

@ -0,0 +1,6 @@
{
"require": {
"slim/slim": "^3.0",
"hiropeke/slim-blade-view": "^0.1.1"
}
}

40
example/public/index.php Normal file
View File

@ -0,0 +1,40 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
// Slim Settings
$config = [
'settings' => [
'displayErrorDetails' => true, // set to false in production
// Renderer settings
'renderer' => [
'blade_template_path' => __DIR__ . '/../views', // String or array of multiple paths
'blade_cache_path' => __DIR__ . '/../cache', // Mandatory by default, though could probably turn caching off for development
],
],
];
// Create Slim app
$app = new \Slim\App($config);
// Fetch DI Container
$container = $app->getContainer();
// Register Blade View helper
$container['view'] = function ($container) {
return new \Slim\Views\Blade(
$container['settings']['renderer']['blade_template_path'],
$container['settings']['renderer']['blade_cache_path']
);
};
// Define named route
$app->get('/hello/{name}/', function ($request, $response, $args) {
return $this->view->render($response, 'profile', [
'name' => $args['name'],
]);
})->setName('profile');
// Run app
$app->run();

View File

@ -0,0 +1 @@
Hello, {{ $name }}