Views
Saturn uses plain PHP files for the view layer. These files can be placed in any views subdirectory. Using a view is as simple as displaying the output from the view function.
The following example will show the contents of either /application/about/views/example.php or /application/views/example.php.
application/about/about.php
class About extends \Core\Controller
{
public function index()
{
echo view('example');
}
}
The following example will show the contents of /application/news/views/example.php, /application/about/views/news/example.php or /application/views/news/example.php.
application/about/about.php
class About extends \Core\Controller
{
public function index()
{
echo view('news/example');
}
}
Passing data
The view function accepts an associative array as secondary parameter. Data in this array will be expanded to variables within the view, using the array keys as variable names.
application/about/about.php
class About extends \Core\Controller
{
public function index()
{
echo view('example',[
'title' => 'About us'
]);
}
}
application/about/views/example.php
<section id="about">
<h1><?=$title?></h1>
</section>
While it is possible to call te view function from within another view — keep in mind that when creating complex view hierarchies, using a Layout might be preferable.