dopesong / PHP-View

A Simple PHP Renderer for Slim3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP Renderer

This is a renderer for rendering PHP view scripts into a PSR-7 Response object. It works well with Slim Framework 3.

Usage With Slim 3

use Slim\Views\PhpRenderer;

include "vendor/autoload.php";

$app = new Slim\App();
$container = $app->getContainer();
$container['renderer'] = new PhpRenderer("./templates");

$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->renderer->render($response, "/hello.php", $args);
});

$app->run();

Usage with any PSR-7 Project

//Construct the View
$phpView = new PhpRenderer("./path/to/templates");

//Render a Template
$response = $phpView->render(new Response(), "/path/to/template.php", $yourData);

Exceptions

\RuntimeException - if template does not exist

\InvalidArgumentException - if $data contains 'template'

About

A Simple PHP Renderer for Slim3

License:MIT License


Languages

Language:PHP 100.0%