Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Guilherme Nascimento edited this page Jan 16, 2026 · 7 revisions

Note: This documentation covers Inphinit 1.0. For the 2.1 documentation, visit: https://inphinit.github.io/en/docs/views.html

For use first put Inphinit\Viewing\View in your controller (or other script), like this:

<?php
use Inphinit\Viewing\View;

Simple usage:

A simple example:

View::render('foo'); //register ./system/application/View/foo.php

Note: the Views render after App::exec (see ./system/boot/start.php)

You can use multiple views, example:

<?php
namespace Controller;

use Inphinit\Viewing\View;

class Foo
{
    public function about()
    {
        View::render('components.header'); //register ./system/application/View/components/header.php
        View::render('pages.about');       //register ./system/application/View/pages/about.php
        View::render('components.footer'); //register ./system/application/View/components/footer.php
    }
}

Force render

You can use View::forceRender() before if needs force render Views, example:

View::forceRender();
View::render('foo');

This makes Views are rendered before App::exec, use only if necessary.

Passing variables

You can send variables to View using this way:

View::render('foo', array(
    'title' => 'example',
    'foo' => 'foo foo foo',
    'bar' => 'bar bar bar',
    'baz' => 10001
));

For get variables in ./system/application/View/foo.php use:

<!DOCTYPE html>
<html>
<head>
    <title><?php echo $title; ?></title>
</head>
<body>
    <p>$foo: <?php echo $foo; ?></p>
    <p>$bar: <?php echo $bar; ?></p>
    <p>$baz: <?php echo $baz; ?></p>
</body>
</html>

If you using PHP 5.4+ or enable short tags in php.ini (short_open_tag=On) you can use:

<!DOCTYPE html>
<html>
<head>
    <title><?=$title?></title>
</head>
<body>
    <p>$foo: <?=$foo?></p>
    <p>$bar: <?=$bar?></p>
    <p>$baz: <?=$baz?></p>
</body>
</html>

Render View inside another View

You can include View inside another View using like this:

<!DOCTYPE html>
<html>
<head>
    <title><?php echo $title; ?></title>
</head>
<body>
    <?php
    //Render view ./system/application/View/components/header.php
    View::render('components.header');
    ?>

    <p>$foo: <?php echo $foo; ?></p>
    <p>$bar: <?php echo $bar; ?></p>
    <p>$baz: <?php echo $baz; ?></p>

    <?php
    //Render view ./system/application/View/components/footer.php
    View::render('components.footer');
    ?>
</body>
</html>

Views called within by other views are rendered at the same time as the main view

Share data in Views

For share data in all Views use View::data($key, $value) function, for example:

<?php

use Inphinit\Viewing\View;

View::data('foo', 1);
View::data('bar', 2);
View::data('baz', 3);

Route::set('GET', '/', function () {
    View::render('header');

    View::render('home', array(
        'text' => 'Hello, world!'
    ));

    View::render('footer');
});

Route::set('GET', '/about', function () {
    View::render('header');

    View::render('home', array(
        'text' => 'About us!'
    ));

    View::render('footer');
});

In ./system/application/View/header.php put this:

<?php
var_dump('header', $foo, $bar, $baz);

In ./system/application/View/footer.php put this:

<?php
var_dump('footer', $foo, $bar, $baz);

In ./system/application/View/home.php put this:

<?php
var_dump('home', $foo, $bar, $baz, $text);

In ./system/application/View/about.php put this:

<?php
var_dump('about', $foo, $bar, $baz, $text);

If navigate to http://localhost/ will return:

string(6) "header"
string(8) "foo data"
string(8) "bar data"
string(8) "baz data"

string(4) "home"
string(8) "foo data"
string(8) "bar data"
string(8) "baz data"
string(13) "Hello, world!"

string(6) "footer"
string(8) "foo data"
string(8) "bar data"
string(8) "baz data"

If navigate to http://localhost/about will return:

string(6) "header"
string(8) "foo data"
string(8) "bar data"
string(8) "baz data"

string(5) "about"
string(8) "foo data"
string(8) "bar data"
string(8) "baz data"
string(9) "About us!"

string(6) "footer"
string(8) "foo data"
string(8) "bar data"
string(8) "baz data"

Clone this wiki locally