Question

I have an array in my index.php file;

$teamnames = array('bristol_city', 'bristol_thunder', 'bristol_uni', 'exeter_city', 'exeter_uni', 'gloucester', 'horfield', 'taunton');

Then I have a "controller" and I want to pass that array in to the add-report.php view;

$app->get('/report/add', function () use($app) {
    $app->render('add-report.php', array());
});

I have tried adding $teamnames to array() and then trying to do a print_r on the view but all I get is an error;

Type: ErrorException
Code: 8
Message: Undefined variable: teamnames
File: /vagrant/ref-feedback/index.php
Line: 18

I am brand new to Slim and cannot find any documentation on this at all....

Was it helpful?

Solution

You may try this:

$app->get('/report/add', function () use($app) {
    $teamnames = array('bristol_city', 'bristol_thunder', '...');
    $app->render('add-report.php', array('teamnames' => $teamnames));
});

The array will be extracted into the view, so now you may use print_r($teamnames) in the view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top