idealogica/good-view

Extremely simple and standard compliant view implementation of MVC pattern

1.0.4 2021-08-06 09:57 UTC

This package is auto-updated.

Last update: 2024-04-06 16:05:00 UTC


README

1. What is GoodView?

It is a simple MVC view implementation. By default GoodView uses PHP as template engine but it can be adapted to use any. It supports PSR-7 stream rendering so it can be easily used in HTTP middleware. GoodView supports nested views and layout views.

2. Installation

composer require idealogica/good-view:~1.0.0

3. Basic example

$viewFactory = ViewFactory::createStreamViewFactory(
    new StreamFactory(),
    ['content' => '<div>'],
    [__DIR__ . '/templates']
);
$view = $viewFactory->create('test');
$stream = $view->render(); // StreamInterface instance
$contents = $stream->getContents(); // rendered string

templates/test.phtml:

<?php $this->setLayout('layout') ?>
<?= $this->e($content); ?>

templates/layout.phtml:

!<?= trim($content) ?>!

4. License

GoodView is licensed under a MIT License.