O'Reilly logo

Zend Framework 2 Cookbook by Josephus Callaars

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a custom form element and form view helper

Once we keep on developing in Zend Framework 2, and our application keeps on growing, the more it is necessary to stop copy-pasting and just replace all those replicating bits by a class that simply outputs what we want. In ZF2 this can be done easily through view helpers.

How to do it…

In this recipe we'll create our own form element, and corresponding view helper to display it.

Creating the new element

All we have to do is set the type of the element, and that's it. We do the following alterations to the /module/Application/src/Application/Form/Element/Video.php file, let's take a look on what the code should look like:

<?php // Set our namespace just right namespace Application\Form\Element; // ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required