Excuses voor de titel, kon niets beters verzinnen. Ben hier al sinds gister avond mee bezig geweest maar wil het niet werkend krijgen. Ik krijg de volgende 2 error's bij het uitvoeren van de index.php. Alle bestanden staan ook hieronder.
Notice: Undefined variable: _smarty in C:\wamp\www\project2\templates\home.php on line 3
Fatal error: Call to a member function assign() on a non-object in C:\wamp\www\project2\templates\home.php on line 3
Kan iemand mij vertellen wat ik hier fout doe, over het hoofd zie en veel frustaties aan beleef voor een simpel experiment?
index.php
includes/smt.class.php
templates/home.tpl
templates/home.php
smtconfig.php
Notice: Undefined variable: _smarty in C:\wamp\www\project2\templates\home.php on line 3
Fatal error: Call to a member function assign() on a non-object in C:\wamp\www\project2\templates\home.php on line 3
Kan iemand mij vertellen wat ik hier fout doe, over het hoofd zie en veel frustaties aan beleef voor een simpel experiment?
index.php
PHP: filename
1
2
3
4
5
| require_once('includes/smt.class.php'); $_smarty = new SMTemplate(); $_smarty->render('home'); |
includes/smt.class.php
PHP: filename
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| require_once('./templates/lib/Smarty.class.php'); require_once('./smtconfig.php'); class SMTemplate{ public $_smarty; function __construct(){ $this->_smarty = new Smarty(); global $smtemplate_config; $this->_smarty->template_dir = $smtemplate_config['template_dir']; $this->_smarty->compile_dir = $smtemplate_config['compile_dir']; $this->_smarty->cache_dir = $smtemplate_config['cache_dir']; $this->_smarty->configs_dir = $smtemplate_config['configs_dir']; } function render($template){ require('./templates/' .$template. '.php'); $this->_smarty->display($template. '.tpl'); } } |
templates/home.tpl
HTML:
1
2
3
4
5
6
7
8
9
10
11
| <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Home</title> <link rel="stylesheet" href="/css/master.css" type="text/css" media="screen" title="no title" charset="utf-8" /> </head> <body> <p>Hello {$Name}</p> </body> </html> |
templates/home.php
PHP: filename
1
| $_smarty->assign('Name', 'Fred'); |
smtconfig.php
PHP: filename
1
2
3
4
5
6
7
| $smtemplate_config = array( 'template_dir' => 'templates/', 'compile_dir' => 'templates/lib/templates_c/', 'cache_dir' => 'templates/lib/cache', 'configs_dir' => 'templates/lib/configs/', ); |
HOI.