Sergey Romanov
Sergey Romanov

Reputation: 3080

ZF2: Zend Framework 2 - how to render output without layout

I know that I can use this

public function providerAction()
{
    $result = new ViewModel();
    $result->setTerminal(true);

   return $result;
}

But how do I pass variables to view? Before I did this

return array('items' => $items);

But now I have only one option either return array and then layout is there or return $result then variables are not in the view.

Upvotes: 7

Views: 9856

Answers (2)

Patito
Patito

Reputation: 326

The previous answer works perfectly. I just want to add that instead of using setVariables you can also pass your variables directly when instantiating the ViewModel like this:

$result = new ViewModel(array('items' => $items));

Upvotes: 2

AlloVince
AlloVince

Reputation: 1655

In your example you could write like this:

public function providerAction()
{
    $result = new ViewModel();
    $result->setTerminal(true);
    $result->setVariables(array('items' => 'items'));
    return $result;
}

Upvotes: 26

Related Questions