Sandbox Home  |  OmegaSoft Homepage  |  Products & Services  |  About OmegaSoft


 


Code Libraries


Projects & Resources

Interface Model Engine

The Interface Model Engine enables separation of the HTML (user interface) and PHP class code (business model), allowing each layer to operate independently of one another.

The advantages of the IME are; effective separation of interface/business models, flexible presentation and code reusability.

  • HTML and PHP can be completely separated. PHP only needs to return variables to the IME class for inclusion into HTML file.

  • Presentation HTML can be completely changed, without affecting any PHP code.

  • HTML templates can be reused across a whole website, using a single template file. Allowing for changes to be instantly propagated throughout the entire website.

How to use the IME class

HTML template code

<html>
<head>
<title>{TITLE}</title>
</head>
<body>
<p>My name is {NAME}.
</body>
</html>

PHP template engine for simple variable tag replacement

<?php

// Instantiate a new template object 
$html_tpl = &new stel_engine('template.html'); 

// Define parameters for the class 
$tags = array(    'TITLE' => ‘My Website’,
‘NAME’ => 'John Doe'); 

// Parse template file 
$html_tpl->parse_template($tags);

// Display to screen
print $html_tpl->display();

?>

The Interface Model Engine also allows for rows of data to be displayed, by splitting the repetitive parts of the template by using a user-defined HTML comment (by default this uses a string: SPLIT)

<!--section (int) reference: 0-->
<html>
<head></head>

<body>
<p>My name is {NAME}.
<!--SPLIT--><!--section (int) reference: 1-->
<p>{JOBS}
<!--SPLIT--><!--section (int) reference: 2-->
</body>
</html>

The parse_template() method allows for multiple rows of duplication within a HTML document.

<?php

// Instantiate a new template object 
$html_tpl = &new stel_engine('template.html'); 

// Define parameters for the class 
$tags = array(‘NAME’ => 'John Doe');

// Parse template file 
$html_tpl->parse_template($tags0);

// Loop through the dataset
for($i 0$i count($dataset); $i++)
{
    
$tags = array(‘JOBS’ => $dataset[$i]);
    
$html_tpl->parse_template($tags1);
}

// Parse rest of the template
$html_tpl->parse_template(array(), 2);

// Display to screen
print $html_tpl->display();

?>

The parse_template() method tags the given variables as an array of tags and parses the tags from the HTML and replaces them with the HTML for any given HTML segment.

void parse_template ( array tags [, int section )

  • tags: array of tags, where the key is the HTML tag and the value is the variable where the data is stored.

  • section: an integer pointing to the HTML section that is being parsed. The first section always starts at 0.

Download

Version Information

1.0 IME class named stel_engine

1.2 Allows template splitting and datasets

2.1 PHP 5 compatibility added, additional class to extend IME for stel_engine naming on older applications

2.2 Updated mutliple nest problems (bug40) and added increaced type checking (bug39)

Web services using the IME

The following services use the Interface Model Engine

  • OmegaSoft.co.uk website

  • OmegaSoft Traffic Monitor

  • OmegaSoft iForum

  • PathSearch


© Copyright 2008  |  Terms of Use  |  OmegaSoft Homepage  |  Feedback