仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 4225|回复: 20
打印 上一主题 下一主题

[学习教程] PHP教程之PHP教程:设置装备摆设smarty开辟情况

[复制链接]
逍遥一派 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:44:19 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
模仿的不光是模仿,模仿的同时在加改进,就成了自己的作品了。   </p> 起首到 http://www.smarty.net 高低载最新的smarty模板引擎,解压Smarty-2.6.26.zip,更名Smarty-2.6.26目次为smarty。
拷贝smarty目次到你但愿的目次 D:\xampp\xampp\smarty。
在php.ini的include_path到场smarty库目次,以下:
include_path = “.;D:\xampp\xampp\php\PEAR;D:\xampp\xampp\smarty\libs”
在你的php项目目次新建两个子目次放设置装备摆设文件和模板:config 和templates
D:\xampp\xampp\htdocs\config
D:\xampp\xampp\htdocs\templates
smarty项目目次新建两个目次cache和templates_c寄存缓存和编译过的模板:
D:\xampp\xampp\smarty\cache
D:\xampp\xampp\smarty\templates_c
在需求挪用smarty库的php文件中写入代码:
1
2
3
4
5
6
7
8
9
10
11
//this is D:\xampp\xampp\htdocs\index.php
//load smarty library
require('Smarty.class.php');

$smarty=new Smarty();
$smarty->template_dir='d:/xampp/xampp/htdocs/templates'; //指定模板寄存目次
$smarty->config_dir='d:/xampp/xampp/htdocs/config';//指定设置装备摆设文件目次
$smarty->cache_dir='d:/xampp/xampp/smarty/cache';//指定缓存目次
$smarty->compile_dir='d:/xampp/xampp/smarty/templates_c';//指定编译后的模板目次
$smarty->assign('name','fish boy!');
$smarty->display('index.tpl'); 再新建一个D:\xampp\xampp\htdocs\templates\index.tpl文件
1
2
3
4
5
6
7
8
9
10
<html>
<head><title>hello,{$name}!</title>
<script language="javascript" type="text/javascript">
    alert('{$name}');
</script>
</head>
<body>
hello,{$name}!
</body>
</html> 翻开http://localhost/index.php 应当会弹出fish boy!正告,然后内容为hello,fish boy!!的页面。
咱们可以改善一下,不成能每次需求smarty写这么多设置装备摆设代码吧。
新建文件 D:\xampp\xampp\htdocs\smarty_connect.php
1
2
3
4
5
6
7
8
9
10
11
//load smarty library
require('Smarty.class.php');
class smarty_connect extends Smarty
{   function smarty_connect()
    {//每次机关主动挪用本函数
        $this->template_dir='d:/xampp/xampp/htdocs/templates';
        $this->config_dir='d:/xampp/xampp/htdocs/config';
        $this->cache_dir='d:/xampp/xampp/smarty/cache';
        $this->compile_dir='d:/xampp/xampp/smarty/templates_c';
    }
} D:\xampp\xampp\htdocs\index.php改成:
1
2
3
4
     require('smarty_connect.php');
    $smt=new smarty_connect;
    $smt->assign('name','fish boy!');
    $smt->display('index.tpl'); index.tpl文件不变,翻开localhost/index.php,呈现了一样的输入。
怎么样出来了吧,怎么样自己也可以写出php程序了,虽然离职业和专业的人还有很远,但是好的开始是成功的一半。这个时候改怎么做了呢。现在就是拿1本高手推荐的书,重头到尾读1遍,我说的这个读是自己看。
逍遥一派 该用户已被删除
沙发
 楼主| 发表于 2015-4-10 08:36:29 | 显示全部楼层
当然这种网站的会员费就几十块钱。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-23 01:34

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表