smarty 简单留板 分页、静态、缓存等功能的用法

作者:袖梨 2022-07-02

YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.***w3.org/TR/REC-html40/loose.dtd">

smarty的设置

;/********

[database]
hostname = localhost
username = root
password = 123456
dbname = tbb

[html]
web_path =

caching = false
compile_check = true
cache_dir = /smarty_file/cache
compile_dir = /smarty_file/compile
template_dir = /smarty_file/template
;*/
;?>

index.htm

http://www.*w**3.org/1999/xhtml">




guestbook



{{foreach from = $rs item = item}}




{{/foreach}}



{{$item.name}}: {{$item.content}}

一共有{{$pages}}页
{{$total}}条数据
每页显示{{$rows}}条

{{foreach from = $links item = num}}
{{if $num == $current_page}}
{{$num}}
{{else}}

{{/if}}
{{/foreach}}
















用户名
内容


下面是显示程序
define('ROOT_PATH', dirname(__FILE__));

require_once ROOT_PATH . '/lib/m_html.class.php';
require_once ROOT_PATH . '/lib/m_db.class.php';
$page = $_GET['page'];

$mdb = new m_db();
$html = new m_html('/test_' . $page . '.html', 30);

$num = $mdb->fetch_one('select count(*) as num from test');
$page_arr = $mdb->page($num['num'], $page, 7, 4);

$rs = $mdb->fetch_all('select * from test order by id desc limit ' . $page_arr['start'] . ',' . $page_arr['rows']);

$html->assign('rs', $rs);
$html->assign('web_path', $html->config['web_path'] . '/');
$html->assign($page_arr);
$html->render('index.htm', '/test_' . $page_arr['current_page'] . '.html');
?>

下面是保存留言代码
define('ROOT_PATH', dirname(__FILE__));

require_once ROOT_PATH . '/lib/m_db.class.php';
require_once ROOT_PATH . '/lib/m_string.class.php';

$_POST = m_string::addslashes($_POST);
$mdb = new m_db();
$mdb->add('test', array('name', 'content'), array($_POST['username'], $_POST['content']));

header('location:test.php');
?>

CREATE TABLE `test` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`content` tinytext NOT NULL,
PRIMARY KEY (`id`)
)

相关文章

精彩推荐