add example codes.
This commit is contained in:
1
example/.gitignore
vendored
Normal file
1
example/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/vendor
|
2
example/cache/.gitignore
vendored
Normal file
2
example/cache/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
6
example/composer.json
Normal file
6
example/composer.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"slim/slim": "^3.0",
|
||||||
|
"hiropeke/slim-blade-view": "^0.1.1"
|
||||||
|
}
|
||||||
|
}
|
40
example/public/index.php
Normal file
40
example/public/index.php
Normal 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();
|
1
example/views/profile.blade.php
Normal file
1
example/views/profile.blade.php
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hello, {{ $name }}
|
Reference in New Issue
Block a user