Book Image

Zend Framework 2.0 by Example: Beginner's Guide

By : Krishna Shasankar V
Book Image

Zend Framework 2.0 by Example: Beginner's Guide

By: Krishna Shasankar V

Overview of this book

<p>ZF2 is the latest update to the well-known Zend Framework. This version has considerably eased the process of building complex web applications with minimal development effort using plug and play components. ZF2 also provides a highly robust and scalable framework for developing web applications.</p> <p>"Zend Framework 2.0 by Example: Beginner’s Guide" will guide you through the process of developing powerful web applications using ZF2. It covers all aspects of Zend Framework application development right from installation and configuration; the tasks are designed in a way that readers can easily understand and use them to build their own applications with ease.</p> <p>"Zend Framework 2.0 by Example: Beginner’s Guide" begins with the basic installation and configuration of the Zend Framework. As you progress through the exercises, you will become thoroughly acquainted with ZF2. With this book, you will learn about the basic concepts of building solid MVC web applications using Zend Framework 2.0. The detailed step-by-step instructions will enable you to build functionality such as a group chat, a file &amp; media sharing service, search, and a simple store to name a few. You will also use a wide range of external modules to implement features that are not natively available. By the end of the book, you will be well versed in building complex, functionality-rich web applications using Zend Framework 2.0.</p> <p>"Zend Framework 2.0 by Example: Beginner’s Guide" provides everything that you need for building functionality-rich web applications with simple real world examples and tasks.</p>
Table of Contents (18 chapters)
Zend Framework 2.0 by Example Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – creating controllers and views


Now that we have created the module, our next step would be having our own controllers and views defined. In this section, we will create two simple views and will write a controller to switch between them:

  1. Navigate to the module location:

    $ cd /var/www/CommunicationApp/module/Users
    
  2. Create the folder for controllers:

    $ mkdir -p src/Users/Controller/
    
  3. Create a new IndexController file, < ModuleName >/src/<ModuleName>/Controller/:

    $ cd src/Users/Controller/
    $ vim IndexController.php
    
  4. Add the following code to the IndexController file:

    <?php
    namespace Users\Controller;
    use Zend\Mvc\Controller\AbstractActionController;
    use Zend\View\Model\ViewModel;
    class IndexController extends AbstractActionController
    {
        public function indexAction()
        {
            $view = new ViewModel();
            return $view;
        }
        public function registerAction()
        {
            $view = new ViewModel();
            $view->setTemplate('users/index/new-user')...