index_php_template.php
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Test script for PHP template
* @author Monte Ohrt <monte at ohrt dot com>
* @package SmartyTestScripts
*/
require('../libs/Smarty.class.php');
class Person
{
private $m_szName;
private $m_iAge;
public function setName($szName)
{
$this->m_szName = $szName;
return $this; // We now return $this (the Person)
}
public function setAge($iAge)
{
$this->m_iAge = $iAge;
return $this; // Again, return our Person
}
public function introduce()
{
return 'Hello my name is '.$this->m_szName.' and I am '.$this->m_iAge.' years old.';
}
}
$smarty = new Smarty();
$smarty->allow_php_templates= true;
$smarty->force_compile = false;
$smarty->caching = true;
$smarty->cache_lifetime = 100;
//$smarty->debugging = true;
$smarty->assign('foo',"'bar'");
$person = new Person;
$smarty->assign('person',$person);
$smarty->assign('array',array('a'=>array('aa'=>'This is a long string'),'b'=>2));
$smarty->display('php:index_view.php');
?>