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 Yii framework


To create a new controller, create a new PHP class inside the controller folder. Name it CookingController.php. The reason for this? You have been doing this for a while now, so you should continue doing it lest your stomach gets angry. Keep cooking, comrade.

How to do it...

To create a new controller, go to a new PHP class. Use the name CookingController.php. Do remember the directory <project-root>/app/controllers. Your controller will look somewhat like the following code:

namespace app\controllers;

use app\models\Cooking;
use Yii;
use yii\web\Controller;

class CookingController extends Controller
{
  public function actionIndex(){
    $items = new Cooking();
    $dishname = 'pizza';
    $ingredients = $items->getIngredients();
    $toppings = $items->getToppings();
    return $this>render('index',array('dishname'=>$dishname,
    'ingredients'=>$ingredients,'toppings' => $toppings));
  }
}

How it works...

On careful examination...