Smarty Variable: Object

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:

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');

Next, build template by create a file named "test.tpl" within template. Enter following code

    id : {$contact->id} <br>
    name : {$contact->name} <br>    
    email : {$contact->email} <br>    
    phone : {$contact->phone} <br>    

Bookmark and Share Tag: smarty, template, variable, object Category: PHP Classes Post : May 02nd 2008 Read: 46,675


blog comments powered by Disqus