rubellum/slim-blade-view

基于Blade组件构建的Slim Framework 3视图助手

0.1.1 2016-03-11 02:32 UTC

This package is auto-updated.

Last update: 2024-09-25 14:57:56 UTC


README

Build Status License: MIT

这是一个基于Blade组件构建的Slim Framework视图助手。

您可以使用此组件在Slim Framework应用程序中创建和渲染模板。

安装

通过Composer

$ composer require rubellum/slim-blade-view

需要Slim Framework 3和PHP 5.5.0或更高版本。

用法

// Slim Settings
$config = [
    'settings' => [
        'displayErrorDetails' => true, // set to false in production

        // Renderer settings
        'renderer'            => [
            'blade_template_path' => 'path/to/views', // String or array of multiple paths
            'blade_cache_path'    => 'path/to/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();

测试

$ phpunit

许可证

MIT许可证(MIT)。请参阅许可证文件获取更多信息。