smarty简单应用实例,smarty应用实例
本文讲述了smarty简单应用实例。分享给大家供大家参考,具体如下:
<?php require 'smarty/libs/Smarty.class.php'; $smarty = new Smarty; $smarty->template_dir="smarty/templates/templates"; $smarty->compile_dir="smarty/templates/templates_c"; $smarty->config_dir="smarty/templates/config"; $smarty->cache_dir="smarty/templates/cache"; $hello = "Hello World!"; $smarty->compile_check = true; //$smarty->debugging = true; $smarty->debugging = false; $smarty->caching=true; $conn=mysql_connect("localhost", "root","root"); //打开MySQL服务器连接 mysql_select_db("lava_guess"); //链接数据库 mysql_query("set names utf8"); //解决中文乱码问题 $sql_list="Select * from t_sys_msg Order by id desc limit 0,10"; $result_list=mysql_query($sql_list); //执行sql语句,返回结果 //把记录集转换为数组 while($rs_list=mysql_fetch_array($result_list)) { $msg_array[]=$rs_list; } $array[] = array("newsID"=>1, "newsTitle"=>"第1条新闻"); $array[] = array("newsID"=>2, "newsTitle"=>"第2条新闻"); $array[] = array("newsID"=>3, "newsTitle"=>"第3条新闻"); $array[] = array("newsID"=>4, "newsTitle"=>"第4条新闻"); $array[] = array("newsID"=>5, "newsTitle"=>"第5条新闻"); $array[] = array("newsID"=>6, "newsTitle"=>"第6条新闻"); $smarty->assign("newsArray", $array); $smarty->assign("hello",$hello); //赋值 $smarty->assign("msglist",$msg_array); $smarty->display('index.tpl'); ?>
模板文件:index.tpl
<html> <head> <metahttp-equiv="Content-Type" content="text/html;charset=utf-8"> <title>Smarty</title></head> <body> <hr> {$hello} <hr> {section name=loop loop=$msglist} id: {$msglist[loop].id}--{$msglist[loop].title}----{$msglist[loop].receiver}<br> {/section} <hr> {section name=loop loop=$newsArray} 新闻编号:{$newsArray[loop].newsID}<br> 新闻标题:{$newsArray[loop].newsTitle}<br><hr> {sectionelse} 对不起,没有任何新闻输入! {/section}
希望本文所述对大家基于smarty模板的php程序设计有所帮助。

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

드림위버 CS6
시각적 웹 개발 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구
