Jump to content

how to configure smarty with wampserver

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Hi all,i need help please.Does anyone ever configure smarty with wampserver before?Please teach me how to do it..Thanks a lot...

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
no more different than on any other server.

// first, you need to include your smarty

require_once("c:/path/to/smarty/libs/Smarty.php");

// instantiate smarty

$smarty = new Smarty();

//you need to set a few variables:

// say you put them in subs to your project,

// you need to create these directories

$smarty->$template_dir = "/templates";

$smarty->$compile_dir = "/compile"

then you're up and running...

me myself create the compile directory where I install Smarty, to avoid it from beeing in webroot, example c:/path/to/smarty/compile

#3
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Then i don't have to add the path on the php.ini the include_path?Thanks..

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
exactly. smarty does not require any extra rights at all on the server

#5
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Thanks,i've got it working now.I want to ask again,do you have any tutorial reference about using it with mysql?Thanks..

#6
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
it doesn't need any special tutorial. just store your data in arrays and had it to smarty, and loop through the arrays in smarty with the foreach or section loop tools.

#7
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Do you have any example?Thanks...

#8
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
in php:
[highlight="php"]
$smarty = new Smarty();
// set necessary configs
$res = mysql_query("select a, b from table");
while ($row = mysql_fetch_array($res)) {
$arr[a] = b;
}
$smarty->assign("tabledata", $arr);
$smarty->display("test.tpl");
[/highlight]

then in your test.tpl:
[highlight="Smarty"]
<html>
<head></head>
<body>
<table>
{foreach from=$tabledata item=data}
<tr><td>{$data}</td></tr>
{/foreach}
</table>
</body></head>
[/highlight]