phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Smarty Variable: Object

Tag: smarty, template, variable, object   Category: PHP Classes
post: 02 May 2008 read: 245


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>



| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting