View previous topic :: View next topic |
Author |
Message |
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
Posted: Tue Mar 23, 2004 5:25 am Post subject: How do I use funtion in tpl files ? |
|
|
1. {php}echo TimePassed($stardebug, 3){/php}
but the variable "$stardebug" incepts nothing .
2. register_funtion ? I don't know how to use it .tell me , thanks
My Function :
index.php
----------------
[php:1:b46e6afb49] $stardebug = GetMicrotime();
..........
..........
..........
$Smarty->display("footer.tpl");
function GetMicrotime()
{
$microtime = microtime();
$microtime = explode(" ", $microtime);
$microtime = doubleval($microtime[1]) + doubleval($microtime[0]);
return $microtime;
}
function TimePassed($stardebug, $length = 3)
{
$endtime = GetMicrotime();
$time_passed = ($endtime - $stardebug) * 1000;
$time_passed = number_format($time_passed, $length, ".", "");
return $time_passed;
}
[/php:1:b46e6afb49]
footer.tpl
-----------------
Code: | ................
Processed in {php}echo TimePassed($stardebug){/php} ms .
................
|
I don't know how to modify footer.tpl ..help me , thanks very much . _________________ Something comes soon ...
http://www.showtop.net
http://www.openphp.cn |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
|
Back to top |
|
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
Posted: Tue Mar 23, 2004 7:02 am Post subject: |
|
|
Thank You Very Much . Thanks For You Help .
I test your code .
Smarty error: [in main.tpl line 9]: syntax error: unrecognized tag 's_math' (Smarty_Compiler.class.php, line 551)
I don't know why . I am new for Smarty .
I view some topics of yours , Say PEAR::DB is slow ? Yes ! Do nothing but pass 50 or more ms .... only for include mysql.php file . I don't know how is Smarty . _________________ Something comes soon ...
http://www.showtop.net
http://www.openphp.cn |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Mar 23, 2004 7:15 am Post subject: |
|
|
Hi ShenKong,
s_math is another plugin which you can find in the plugin forum. It is not required to use the timeblock plugin--I included it in my example mainly because I wrote the timeblock plugin to compare the speed of the s_math plugin to the built-in math functionality of the older 2.5.0 version of Smarty.
I have been using DBX as my db abstraction layer -- it is thin, fast and as a module, has no significant start-up time. Unfortunately, it may not be available on all hosts since it is not enabled by default.
As for Smarty's performance, it is considered good as far as PHP template engines go. A nice thing about Smarty is that it only loads its plugins (and even parts of its core engine) when those parts are required, helping reduce overall load times. The caching feature can also help reduce overall load.
cheers! |
|
Back to top |
|
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
Posted: Tue Mar 23, 2004 8:11 am Post subject: |
|
|
Thanks ..
I consider SQLite will be popular . Yestoday I viewed someting about it . It seems very good . Compare with ASP/Access , future the application must be easy to install . but now install a PHP application with MySQL (or other DBMS) is hard for some people .........en , so I must choose a db abstraction layer if future I change DBMS mybe easy and modify code few . . . May PHP5 enable DBX by default ? They should make DBX perfect , Its funtions are few . But I saw a topic written by Zeev , he said DBX will be use by default db abstraction layer ,is that true ? I can't found that topic now , it is on zend.com / ask a question for php5/ .
My English is poor .. hope you can understand .
There are few informations about PHP with Chinese ... _________________ Something comes soon ...
http://www.showtop.net
http://www.openphp.cn |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Mar 23, 2004 8:35 am Post subject: |
|
|
Quote: | FROM: http://zend.com/php/ask_experts.php (zeev, andi)
Q: Will be dbx extension keeped in PHP 5? Or it will be removed?
A: I haven't heard of talk about removing it. However, we are expecting a new DB abstraction extension to appear at some point (called PDO - PHP Data Objects). I am not sure what will be the fate of DBX after that. In any case, I'd expect it to stay around, if not as part of the main distribution then as part of the PECL repository. |
My understanding is that there are no releases of PDO at this time and it may or not be completed by the time PHP5 is fully released. I have been pleased to see many improvements in the DBX library since it was first released. I'm interested in PHP5, naturally, but I work with PHP4. I expect to be using DBX for the quite some time.
Anyways, sorry for straying off-topic -- I'll try to stick the Smarty stuff here |
|
Back to top |
|
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
Posted: Wed Mar 24, 2004 3:28 am Post subject: |
|
|
Thanks .
Another question :
I have some DB queries , I use cache like this:
[php:1:c7df4009d5]
<?php
$Smarty->caching = 1;
$Smarty->cache_lifetime = 300;
//................................
// ........DB queries ........
//................................
$Smarty->display("main" . TPL);
?>
[/php:1:c7df4009d5]
but , It doesn't do what I want . The DB query also run after the cache files exist..... Do I need to add the DB query in the tpl files ? Or any other ways? Thanks for your work on Smarty . _________________ Something comes soon ...
http://www.showtop.net
http://www.openphp.cn |
|
Back to top |
|
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
Posted: Wed Mar 24, 2004 3:30 am Post subject: |
|
|
I think I know how to do now . Use is_cached() .
But From my test , it can't run ,why ?
print_r($Smarty->is_cached("main.tpl"));
return nothing ........ _________________ Something comes soon ...
http://www.showtop.net
http://www.openphp.cn |
|
Back to top |
|
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Mar 24, 2004 4:31 am Post subject: |
|
|
hi again.
hmm, is_cached() works perfectly. Did you set-up you cache directory? |
|
Back to top |
|
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
|
Back to top |
|
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
Posted: Wed Mar 24, 2004 4:46 am Post subject: |
|
|
Oh my god . It is something wrong with this language class , how do I do now ....... I only use smaty class , every thing is OK . _________________ Something comes soon ...
http://www.showtop.net
http://www.openphp.cn |
|
Back to top |
|
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
Posted: Wed Mar 24, 2004 5:32 am Post subject: |
|
|
Watch codes is very tired ... Now everything seems OK .
Add these codes in smartyML class :
[php:1:e2644ac148] function is_cached($_smarty_tpl_file, $_smarty_cache_id = null, $_smarty_compile_id = null) {
// We need to set the cache id and the compile id so a new script will be
// compiled for each language. This makes things really fast
$_smarty_compile_id = $this->language->getCurrentLanguage().'-'.$_smarty_compile_id;
$_smarty_cache_id = $_smarty_compile_id;
// Now call parent method
return parent::is_cached( $_smarty_tpl_file, $_smarty_cache_id, $_smarty_compile_id);
}[/php:1:e2644ac148] _________________ Something comes soon ...
http://www.showtop.net
http://www.openphp.cn |
|
Back to top |
|
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
Posted: Wed Mar 24, 2004 1:25 pm Post subject: |
|
|
mmh~~ One suggestion For smarty.class.php
Line 1728
[php:1:ab8ff207e9] if (!($fd = @fopen($filename, 'r'))) {
return false;
}[/php:1:ab8ff207e9]
Change as
[php:1:ab8ff207e9] if (file_exists($filename)) {
$fd = @fopen($filename, 'r');
} else {
return false;
}[/php:1:ab8ff207e9] _________________ Something comes soon ...
http://www.showtop.net
http://www.openphp.cn |
|
Back to top |
|
ShenKong Smarty Rookie
Joined: 20 Jan 2004 Posts: 27
|
Posted: Thu Mar 25, 2004 2:57 pm Post subject: |
|
|
Hi , I come back again ... Some question :
1. Does Smarty support Switch ?
My code :
Code: | <head>
<title>{$smarty.const.WEB_NAME} -
{if $smarty.get.page eq "soft"}
##LANG_CLASSSOFTNAME##
{elseif $smarty.get.page eq "user"}
##LANG_CLASSUSERNAME##
{elseif $smarty.get.page eq "article"}
##LANG_CLASSARTICLENAME##
{elseif $smarty.get.page eq "news"}
##LANG_CLASSNEWSNAME##
{elseif $smarty.get.page eq "forum"}
##LANG_CLASSFORUMNAME##
{elseif $smarty.get.page eq "review"}
##LANG_REVIEWSPAGE##
{elseif $smarty.get.page eq "register"}
##LANG_REGISTERPAGE##
{else}
##LANG_MAINPAGE##
{/if}{$web_title}</title> | [/code]
It is too discommodious ....... Any other way ? ##..## will turn to the language
2. Use DB like this ?
[php:1:a5ee1ff731] $query = "Select
id, title, view_num, add_time
From
" . PRE . "topics
Order By id Desc Limit 8";
$result = $DB->query($query);
$i = 0;
while($row = $result->fetchRow())
{
$row[3] = date("y-m-d H:i:s", $row[3]);
$topics[$i] = $row;
$i++;
}
$result->free();
$Smarty->assign("topics", $topics);
[/php:1:a5ee1ff731]
tpl................
Code: | <table width="245" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><img src="{$smarty.const.IMAGE_DIR}main_communion.gif" alt="" width="239" height="13" /></td>
</tr>
<tr>
<td style="height:10px;"></td>
</tr>
<tr>
<td align="left">
<ul>
{section name=num loop=$topics}
<li style="color: #666666;"><a href="{$smarty.const.MAIN_PAGE}?page=news&id={$news[num].0}">{$topics[num].1}</a><br /><span style="font-size:9px; color:#BBBBBB;">{$topics[num].3} | View Num : {$topics[num].2}</span></li>
{/section}
</ul></td>
</tr>
<tr>
<td align="left" valign="top" style="height:20px; border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:#3D658C; "><a href="{$smarty.const.MAIN_PAGE}?page=forum"><img src="{$smarty.const.IMAGE_DIR}more.gif" alt="##LANG_MORENEWTOPICS##" width="33" height="8" /></a></td>
</tr>
</table> |
I don't know weather is correct to do like this ...........
3. Article system ... URL like this :
http://localhost/index.php?id=1
http://localhost/index.php?id=1
index.php.................
[php:1:a5ee1ff731]
<?php
$id = $_GET['id'];
include "header.php";
$smarty->display("main.tpl");
include "footer.php";
?>
[/php:1:a5ee1ff731]
How to use cache when the $id changed ? ? _________________ Something comes soon ...
http://www.showtop.net
http://www.openphp.cn |
|
Back to top |
|
|