4
私はスマートには本当に新しいです。私はどのようにスマートでPHP関数のセットを使用するかを知りたいと思います。私はいくつかの機能をすぐに使用できることを理解しています。SmartyでPHP関数のセットを使用するにはどうすればいいですか?
例:私はSmartyのと一緒にPDOを使用してい{$my_string|strip_tags}
。私の投稿を取得するコードを以下に見てください
$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からURLを作成します。だから私は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