Advertisement
edgarsBurtnieks

Untitled

Jul 27th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. BASE CONTROLLER
  2. ---------------------------------
  3. <?php
  4.     interface RenderInterface {
  5.         public function render(string $template, array $contents = []) : string;
  6.     }
  7.  
  8.     abstract class Render implements RenderInterface {
  9.         public function render (string $template, array $contents = []) : string {
  10.             return include $template;
  11.         }
  12.     }
  13.  
  14. CARS CONTROLLER
  15. ---------------------------------
  16. <?php
  17.     include 'BaseController.php';
  18.     include 'Models/Cars.php';
  19.  
  20.     class CarsController extends Render {
  21.         public function carsAction () {
  22.             $listOfCars = [
  23.                 'Toyota',
  24.                 'Ford',
  25.                 'Audi',
  26.                 'Nissan',
  27.                 'Mercedes',
  28.                 'Opel',
  29.                 'Tesla',
  30.             ];
  31.  
  32.             $cars = new Cars($listOfCars);
  33.             $randomCars = $cars->getRandomCars();
  34.  
  35.             $template = 'Views/cars.view.php';
  36.             $templateVariables = [
  37.                 'cars' => $randomCars,
  38.             ];
  39.  
  40.             return Render::render($template, $templateVariables);
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement