Hi all,i need help please.Does anyone ever configure smarty with wampserver before?Please teach me how to do it..Thanks a lot...
how to configure smarty with wampserver
Started by yonghan, Mar 10 2009 03:50 AM
7 replies to this topic
#1
Posted 10 March 2009 - 03:50 AM
|
|
|
#2
Posted 10 March 2009 - 04:56 AM
no more different than on any other server.
me myself create the compile directory where I install Smarty, to avoid it from beeing in webroot, example c:/path/to/smarty/compile
// 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
Posted 10 March 2009 - 06:41 AM
Then i don't have to add the path on the php.ini the include_path?Thanks..
#4
Posted 10 March 2009 - 07:07 AM
exactly. smarty does not require any extra rights at all on the server
#5
Posted 12 March 2009 - 02:39 AM
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
Posted 12 March 2009 - 05:39 AM
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
Posted 12 March 2009 - 07:12 AM
Do you have any example?Thanks...
#8
Posted 12 March 2009 - 08:42 AM
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]
[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]


Sign In
Create Account


Back to top









