Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BASE CONTROLLER
- ---------------------------------
- <?php
- interface RenderInterface {
- public function render(string $template, array $contents = []) : string;
- }
- abstract class Render implements RenderInterface {
- public function render (string $template, array $contents = []) : string {
- return include $template;
- }
- }
- CARS CONTROLLER
- ---------------------------------
- <?php
- include 'BaseController.php';
- include 'Models/Cars.php';
- class CarsController extends Render {
- public function carsAction () {
- $listOfCars = [
- 'Toyota',
- 'Ford',
- 'Audi',
- 'Nissan',
- 'Mercedes',
- 'Opel',
- 'Tesla',
- ];
- $cars = new Cars($listOfCars);
- $randomCars = $cars->getRandomCars();
- $template = 'Views/cars.view.php';
- $templateVariables = [
- 'cars' => $randomCars,
- ];
- return Render::render($template, $templateVariables);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement