morphable/simple-view

A simple view component, easy to implement into any system

v1.0.3-stable 2019-11-17 19:05 UTC

This package is auto-updated.

Last update: 2024-04-18 04:52:20 UTC


README

A simple view component, easy to implement into any system

Usage

<?php

/*
 * index.php
 */


use \Morphable\SimpleView;
use \Morphable\SimpleView\ViewNotFound;

$instance = new SimpleView(__DIR__ . '/views');

/*
you can add anything inside the array in the second parameter, for instance a helper class
there is no template language, just write however you want inside the views
keep in mind the variables you set are usable in the included views after
*/

$result = $instance->serve("home.php", [
    "title" => "hello world",
    "helper" => new Helper()
]);


/*
 * /views/home.php
 */

<?
$data = $this->getData();
$helper = $data['helper'];
?>

<?= $this->include('components/header.php') ?>

<? if (isset($data['title'])): ?>

<h1><?= $helper->translate($data['title'], 'NL') ?></h1>

<? endif; ?>

<?= $this->include('components/footer.php') ?>

Contributing

  • Follow PSR-2 and the .editorconfig
  • Start namespaces with \Morphable\SimpleView
  • Make tests