Smarty Variable Step by Step Tutorial - Part 3: In this post, we will see how to access data from a class.
Create a file named "test.php" enter following code:
<?php
require 'Smarty/libs/Smarty.class.php';
class Contacts{
var $id = 1;
var $name = 'wiwit';
var $email = 'wsiswoutomo at yahoo dot com';
var $phone = '123456789';
}
$contact = new Contacts;
$smarty = new Smarty;
$smarty->assign('title','Contact Detail');
$smarty->assign('contact',$contact);
$smarty->display('test.tpl');
?>
Next, build template by create a file named "test.tpl" within template. Enter following code
<html>
<head>
<title>{$title}</title>
</head>
<body>
id : {$contact->id} <br>
name : {$contact->name} <br>
email : {$contact->email} <br>
phone : {$contact->phone} <br>
</body>
</html>
advertisements
blog comments powered by Disqus

