PHP Classes

View: Generate HTML for page views from variable values

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 73%Total: 185 All time: 8,654 This week: 488Up
Version Licenses PHP version Categories
view 1.1Freely Distributable7HTML, Templates, Design Patterns, PHP 7
Description 

Author

This class can generate HTML for page views from variable values.

It takes the name of a HTML template file that will be used to define the core of a page that will be the current script output.

The class can replace some given variable values in the template and will use the result to replace a main layout HTML template file to generate the final output.

Picture of Ezhaym Najera M
  Performance   Level  
Name: Ezhaym Najera M <contact>
Classes: 3 packages by
Country: Mexico Mexico
Age: ???
All time rank: 331237 in Mexico Mexico
Week rank: 93 Up1 in Mexico Mexico Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

include_once 'View.php';

// Create a new View. By default, it will search for main.html layout
// Crear una nueva Vista. Por default, buscará el layout main.html
$view = new View();

// Set index.html as file to get contents (only name)
// Elegir a index.html como el archivo para el contenido (solo el nombre)
$view->setView('index');

// Add external source files to <head> of Layout
// Agregar archivos externos al <head> del Layout
$view->addHeader('css/styles.css', 'css');
$view->addHeader('js/functions.js');

// Add data to {h} & {w} variables from index.html
// Agregar datos a las variables {h} y {w} de index.html
$view->add([
   
'h' => 'Hello',
   
'w' => 'World!'
]);

// Print view
// Imprimir vista
$view->render();


Details

View

Generate Views from main Layout and HTML files with PHP

simple as:

$view = new View();

// Get contact.html and load into visitor_layout.html
$view->setView('contact', 'visitor_layout');

// Add <script> tag to <head> section
$view->addHeader('js/jquery.min.js');

// Add 'title' variable to <body> section
$view->add(['title' => 'Hello World!']);

// Print on screen
$view->render();

visitor_layout.html example:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Example</title>
        
        {headers}
        
    </head>
    <body>
    
        {content}
    
    </body>
</html>

contact.html example:

<h1>{title}</h1>

  • TODO: - Set Arrays on variable views.

_Cause we can only set strings for now._


  Files folder image Files  
File Role Description
Files folder imagepublic (2 directories)
Files folder imageviews (1 file, 1 directory)
Accessible without login Plain text file demo.php Example Example script
Accessible without login Plain text file README.md Doc. Documentation
Plain text file View.php Class Class source

  Files folder image Files  /  public  
File Role Description
Files folder imagecss (1 file)
Files folder imagejs (1 file)

  Files folder image Files  /  public  /  css  
File Role Description
  Accessible without login Plain text file styles.css Data Auxiliary data

  Files folder image Files  /  public  /  js  
File Role Description
  Accessible without login Plain text file functions.js Data Auxiliary data

  Files folder image Files  /  views  
File Role Description
Files folder imagelayout (1 file)
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  views  /  layout  
File Role Description
  Accessible without login HTML file main.html Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:185
This week:0
All time:8,654
This week:488Up
 User Ratings  
 
 All time
Utility:91%StarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:91%StarStarStarStarStar
Examples:91%StarStarStarStarStar
Tests:-
Videos:-
Overall:73%StarStarStarStar
Rank:133