You can use setVar() or setVars() in the controller’s showAction() method to pass single or multiple variables respectively, directly to the view.

  • $this->view->setVar('productId', $productId);
  • $this->view->setVars( ['username' => $user->username, 'phone' => $contact->phone,] );

Instead of using the above methods, you can also set the variables as $this->view->username = $user->username;

BY Best Interview Question ON 03 Apr 2019