Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 926 Bytes

native.md

File metadata and controls

42 lines (32 loc) · 926 Bytes

Views - Plain PHP

You can use plain php files as your views without any compilation or cache layer. This engine enabled by default and available in the Web application skeleton.

Create view

To create plain PHP view simply put file with .php extension into views directory. Template can be rendered by it's filename:

<?php // test.php
echo "hello world";
public function index(ViewsInterface $views)
{
    return $views->render('test'); // no need to specify the extension
}

All the passed parameters will be available as PHP variables:

public function index(ViewsInterface $views)
{
    return $views->render('test', ['name' => 'Antony']); 
}

Where test.php:

Hello , <?= $name ?>!

Container

You can access the container in your view files via $this->container:

Hello world, <?= $name ?>!

<?php dump($this->container->get(MyService::class)); ?>