如何配置smarty请结合上一篇,我的路径放置也是随着上一篇的。
配置smarty模板的储存位置,和一些的参数。
smarty.ini.php
<?php include("smarty/libs/Smarty.class.php"); $smarty = new Smarty(); $smarty->template_dir="smarty/templates/"; $smarty->compile_dir="smarty/templates_c/"; $smarty->config_dir="smarty/configs/"; $smarty->cache_dir="smarty/cache/"; $smarty->caching=false; $smarty->left_delimiter="<{"; $smarty->right_delimiter="}>"; ?>
生成静态页面的主函数php
main.php
<?php include("smarty/smarty.ini.php"); $smarty = new Smarty(); $conn = mysqli_connect('127.0.0.1:3306','localhost','输入密码','mysql'); if(!$conn){ echo "失败"; }//数据库连接 mysqli_query($conn,'set names utf8'); $sql = "SELECT id,name,date,author,ibsn,douban,douban_link,img,introduce,auth_intro,menu FROM books"; $rs_result = mysqli_query($conn,$sql); while ($row = mysqli_fetch_assoc($rs_result)){ $smarty->assign("name",$row['name']); $smarty->assign("