Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Rob Allen May 19, 2012
file 90 lines (69 sloc) 2.46 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
<?php

namespace Application\Controller;

use Zend\Mvc\Controller\ActionController,
    Zend\View\Model\ViewModel;

class ViewController extends ActionController
{
    public function indexAction()
    {
        return new ViewModel();
    }

    public function respondAction()
    {
        // Send a 501 response
        // Note that we don't need a action view script and the layout script isn't called

        $response = $this->getResponse();
        $response->setStatusCode(501);
        return $response;
    }

    public function nolayoutAction()
    {
        // Turn off the layout. i.e. only render the view script.
        $viewModel = new ViewModel();
        $viewModel->setTerminal(true);
        return $viewModel;
    }
    
    public function differentLayoutAction()
    {
        // Use a different layout
        $this->layout('layout/different');
        
        return new ViewModel();
    }

    public function differentViewScriptAction()
    {
        // Use a different view script
        
        $viewModel = new ViewModel();
        $viewModel->setTemplate('application/view/arbitrary');
        return $viewModel;
    }

    public function addAnotherViewModelToLayoutAction()
    {
        // Use an alternative layout
        $layoutViewModel = $this->layout();
        $layoutViewModel->setTemplate('layout/another');

        // add an additional layout to the root view model (layout)
        $sidebar = new ViewModel();
        $sidebar->setTemplate('layout/footer_one');
        $layoutViewModel->addChild($sidebar, 'footer');

        return new ViewModel();
    }

    function multipleViewModelsAction()
    {
        // Alternative layout
        $layoutViewModel = $this->layout();
        $layoutViewModel->setTemplate('layout/another');

        $sidebar = new ViewModel();
        $sidebar->setTemplate('layout/footer_one');
        $layoutViewModel->addChild($sidebar, 'footer');

        // set up action view model and associated child view models
        $result = new ViewModel();
        $result->setTemplate('application/view/another-action');

        $comments = new ViewModel();
        $comments->setTemplate('application/view/child-comments');
        $result->addChild($comments, 'child_comments');

        $comments = new ViewModel();
        $comments->setTemplate('application/view/another-child');
        $result->addChild($comments, 'another_child');

        return $result;
    }

}
Something went wrong with that request. Please try again.