4
我真的很新來smarty。我想知道如何在smarty中使用一組PHP函數。我明白一些功能可以馬上使用。如何在Smarty中使用PHP函數集
例:{$my_string|strip_tags}
我使用的PDO與智者一起。請參閱下面的代碼,我得到我的帖子
$stmnt = $conn->prepare("SELECT post_id, post_title FROM posts ORDER BY post_id DESC");
$stmnt ->execute();
$row = $stmnt ->fetchAll();
$my_template = new Smarty;
$my_template->debugging = false;
$my_template->caching = true;
$my_template->cache_lifetime = 120;
$my_template->setTemplateDir('./templates/’');
$my_template->assign("row", $row);
$my_template->display('posts.tpl');
//in my smartyposts.tpl
{foreach $row as $r}
//display posts here
{/foreach}
我想使用一些PHP函數從post_title創建網址。所以通常我在做什麼php
<?php
foreach($row as $r){
$post_title = $r[‘post_title’];
$create_link = preg_replace("![^a-z0-9]+!i", "-", $post_title);
$create_link = urlencode($create_link);
$create_link = strtolower($create_link);
?>
<a href="posts/<?php echo $create_link;?>」><?php echo $post_title ;?></a>
<?php } ?>
如何使用smarty實現相同的輸出?我到處搜索,但找不到任何答案。欣賞你的時間。
謝謝。奇蹟般有效。 – Jordyn