Book Image

PhpStorm Cookbook

By : Mukund Chaudhary
Book Image

PhpStorm Cookbook

By: Mukund Chaudhary

Overview of this book

Table of Contents (16 chapters)
PhpStorm Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a controller with the Zend framework


Now's the time to create a new controller. To do that, you will have to perform the following steps:

  1. Create a new class inside <project root>/module/Application/src/Application/Controller.

  2. Name it CookingController, and set the namespace Application\Controller.

  3. Use the namespace for the model since you need the model's methods in your code.

  4. Use the namespace for AbstractActionController as you need to tell Zend that your controller is AbstractActionController.

  5. Use the namespace for ViewModel since you will need to render a view when you run the code. Your controller will look like the following code:

    namespace Application\Controller;
    
    use Application\Model\Cooking;
    use Zend\Mvc\Controller\AbstractActionController;
    use Zend\View\Model\ViewModel;
    class CookingController extends AbstractActionController {
      public function indexAction() {
        $dishname = 'Pizza';
        $items = new Cooking();
        $renderView = new ViewModel(
          array('dishname...