Smarty入门教程二-----使用配置文件避免每次都配置路径
2014-10-17 21:04
477 查看
1. 写一个配置文件smarty.ini.php:
<?PHP
//引用类文件?
require 'smarty/Smarty.class.php';
$smarty = new Smarty;
//$smarty=new Smarty;
//设置各个目录的路径,这里是安装的重点
$smarty->template_dir="templates/templates";
$smarty->compile_dir="templates/templates_c";
$smarty->config_dir="templates/config";
$smarty->cache_dir="templates/cache";
//smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决
$smarty->caching=false;
?>
2. 在使用模板的index.php文件中:
<?php
include "smarty.ini.php";
$title="Smarty-Learn-Test";
$content="Smarty_content哈哈";
$auth="MarcoFly";
$website="www.MarcoFly.com";
$smarty->assign("title",$title);
$smarty->assign("content",$content);
$smarty->assign("auth",$auth);
$smarty->assign("website",$website);
$smarty->display("index.html");
?>
相应的index.html文件:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{$title}</title>
</head>
<body>
<p>内容:{$content}</p>
<p>作者:{$auth}</p>
<p>网址:{$website}</p>
</body>
</html>
<?PHP
//引用类文件?
require 'smarty/Smarty.class.php';
$smarty = new Smarty;
//$smarty=new Smarty;
//设置各个目录的路径,这里是安装的重点
$smarty->template_dir="templates/templates";
$smarty->compile_dir="templates/templates_c";
$smarty->config_dir="templates/config";
$smarty->cache_dir="templates/cache";
//smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决
$smarty->caching=false;
?>
2. 在使用模板的index.php文件中:
<?php
include "smarty.ini.php";
$title="Smarty-Learn-Test";
$content="Smarty_content哈哈";
$auth="MarcoFly";
$website="www.MarcoFly.com";
$smarty->assign("title",$title);
$smarty->assign("content",$content);
$smarty->assign("auth",$auth);
$smarty->assign("website",$website);
$smarty->display("index.html");
?>
相应的index.html文件:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{$title}</title>
</head>
<body>
<p>内容:{$content}</p>
<p>作者:{$auth}</p>
<p>网址:{$website}</p>
</body>
</html>
相关文章推荐
- Smarty入门教程二-----使用配置文件避免每次都配置路径
- PowerShell入门教程之创建和使用配置文件实例
- Smarty环境配置与使用入门教程
- Smarty环境配置与使用入门教程
- Heritrix3.0教程 使用入门(三) 配置文件crawler-beans.cxml介绍
- 使用MiddleGen 产生hibernate的数据库表映射文件--MiddleGen使用--MiddleGen入门教程
- 《Visual C++ 2010入门教程》系列二:安装、配置和首次使用VS2010(转)
- Drools入门-----------环境搭建,分析Helloworld Drools5.0的xls文件转drl文件提升解析效率 使用BRMS的Tomcat6.0配置
- 《Visual C++ 2010入门教程》系列二:安装、配置和首次使用VS2010
- PHP模板之Smarty安装与使用入门教程
- 《Visual C++ 2010入门教程》系列二:安装、配置和首次使用VS2010
- air 移动开发配置文件的使用详细教程
- 配置文件使用绝对路径还是相对路径?
- vi/vim使用入门: vimrc在哪儿?vim配置文件相关问题
- spring配置文件在打包使用时找到不路径问题
- smarty 的模版配置文件的使用
- Spring的Ioc简单使用实例(含XML配置文件路径知识)
- PHP模板之Smarty安装与使用入门教程
- PHP 中使用 Smarty 之二:配置文件在模板变量中的使用
- smarty使用变量(从配置文件读取变量 +Smarty变量调节器)