Zend Basic Tutorial
Zend Forms
Zend Database
Zend Advanced
A View is a .phtml file that handles how data is presented to the user. It's part of the MVC architecture (Model-View-Controller).
Typically, views are stored in:
module/ └── Application/ └── view/ └── application/ └── controller-name/ └── action-name.phtml
🔹 Example: View for AboutController@indexAction
/module/Application/view/application/about/index.phtml
From Controller:
return new ViewModel([ 'title' => 'About Us', 'year' => 2025 ]);
In .phtml file:
<h1><?= $this->title ?></h1> <p>Copyright © <?= $this->year ?></p>
<ul> <?php foreach ($this->users as $user): ?> <li><?= $user['name'] ?> - <?= $user['email'] ?></li> <?php endforeach; ?> </ul>
View Helpers are mini-classes that encapsulate common logic for use in views.
$this->helperName() inside a .phtml file.doctype() & headTitle()<?= $this->doctype('HTML5') ?>
<?= $this->headTitle('My Page Title') ?>
<!DOCTYPE html> <title>My Page Title</title>
headMeta()<?= $this->headMeta()->appendName('viewport', 'width=device-width, initial-scale=1') ?>
<meta name="viewport" content="width=device-width, initial-scale=1">
headLink() for Stylesheets<?= $this->headLink()->appendStylesheet($this->basePath('css/style.css')) ?>
<link href="/css/style.css" rel="stylesheet" type="text/css">
headScript() for JS in <head><?= $this->headScript()->appendFile($this->basePath('js/head.js')) ?>
<script src="/js/head.js" type="text/javascript"></script>
inlineScript() for JS in <body> end<?= $this->inlineScript()->appendFile($this->basePath('js/footer.js')) ?>
<script src="/js/footer.js" type="text/javascript"></script>
escapeHtml()<?php $x = "<b>Hello</b>"; ?> <p>Escaped: <?= $this->escapeHtml($x) ?></p>
<p>Escaped: <b>Hello</b></p>
basePath() for Static Assets<img src="<?= $this->basePath('images/logo.png') ?>">
<img src="/images/logo.png">
url() – Route Generatorhome<a href="<?= $this->url('home') ?>">Home</a>
<a href="/">Home</a>
form() Full HTML Demo$form = new Laminas\Form\Form(); $form->add(['name' => 'email', 'type' => 'Email']); $form->add(['name' => 'submit', 'type' => 'Submit', 'attributes' => ['value' => 'Send']]);
<?= $this->form()->openTag($form) ?>
<?= $this->formElement($form->get('email')) ?>
<?= $this->formElement($form->get('submit')) ?>
<?= $this->form()->closeTag() ?>
<form method="post" action=""> <input type="email" name="email"> <input type="submit" name="submit" value="Send"> </form>
partial() – Include Template<h2><?= $this->escapeHtml($title) ?></h2>
<?= $this->partial('partial/header.phtml', ['title' => 'Hello']) ?>
<h2>Hello</h2>
partialLoop() – Render List of Data<li><?= $this->name ?> - <?= $this->email ?></li>
<ul>
<?= $this->partialLoop('partial/user-row.phtml', [
['name' => 'Sam', 'email' => 'sam@example.com'],
['name' => 'Raj', 'email' => 'raj@example.com']
]) ?>
</ul>
<ul> <li>Sam - sam@example.com</li> <li>Raj - raj@example.com</li> </ul>