In Zend Framework 2, you implement a view as a template file, which is a file
having .phtml
extension ("phtml" stands for PHP+HTML). View templates have such
a name because they usually contain HTML code mixed with PHP code snippets used
for rendering the web pages. Views typically live inside of the view subdirectory
of the module.
In your controller, you use the ViewModel
class for passing variables to the view template. The view model can also be used for setting the view template name (see an example below):
<?php
// IndexController.php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController {
// The "index" action
public function indexAction() {
// Pass two variables to view template
$viewModel = new ViewModel(array('var1'=>$var1, 'var2'=>$var2));
// Set view template name
$templateName= $this->isMobile() ? "index/viewfile_mobile" : "index/viewfile";
$viewModel->setTemplate($templateName);
// Return the view model
return $viewModel;
}
}
If you need a basic explanation of views concept in Zend Framework 2, I would recommend you to read the Using Zend Framework 2 book.