hangouh

Mini render PHP

Mar 19th, 2023
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.43 KB | Software | 0 0
  1. /**
  2.  * class View
  3.  */
  4. class View
  5. {
  6.     /**
  7.      * @var string $view
  8.      */
  9.     private $view;
  10.  
  11.     public function __construct($template, $data)
  12.     {
  13.         extract($data);
  14.         ob_start();
  15.         include($template)
  16.         $this->view = ob_get_clean();
  17.     }
  18.  
  19.     public public function __toString()
  20.     {
  21.         return $this->view;
  22.     }
  23. }
  24.  
  25. echo new View('views/index.php', ['saludo' => 'Hola mundo']);
Add Comment
Please, Sign In to add comment