仓酷云

标题: PHP教程之PHP教程:设置装备摆设smarty开辟情况 [打印本页]

作者: 逍遥一派    时间: 2015-2-3 23:44
标题: PHP教程之PHP教程:设置装备摆设smarty开辟情况
模仿的不光是模仿,模仿的同时在加改进,就成了自己的作品了。   </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-2-4 06:24
兴趣是最好的老师,百度是最好的词典。
作者: 变相怪杰    时间: 2015-2-5 01:23
首先我是坚决反对新手上来就用框架的,因为对底层的东西一点都不了解,造成知识上的真空,会对以后的发展不利。我的观点上手了解下框架就好,代码还是手写。当然啦如果是位别的编程语言的高手的话,这个就另当别论啦。
作者: 再现理想    时间: 2015-2-9 17:56
多看优秀程序员编写的代码,仔细理解他们解决问题的方法,对自身有很大的帮助。
作者: 仓酷云    时间: 2015-2-10 22:51
装在C盘下面可以利用windows的ghost功能可以还原回来(顺便当做是重转啦),当然啦我的编译目录要放在别的盘下,不然自己的劳动成果就悲剧啦。
作者: admin    时间: 2015-2-10 23:41
使用 jquery 等js框架的时候,要随时注意浏览器的更新情况,不然很容易发生框架不能使用。
作者: 精灵巫婆    时间: 2015-2-26 15:37
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
作者: 爱飞    时间: 2015-3-2 23:39
如果你可以写完像留言板这样的程序,那么你可以去一些别人的代码了,
作者: 莫相离    时间: 2015-3-11 07:23
有时候汉字的空格也能导致页面出错,所以在写代码的时候,要输入空格最好用引文模式。
作者: 山那边是海    时间: 2015-3-17 23:09
做为1门年轻的语言,php一直很努力。
作者: 小女巫    时间: 2015-3-18 10:41
个人呢觉得,配wamp 最容易漏的一步就是忘了把$PHP$目录下的libmysql.dll拷贝到windows系统目录的system32目录下,还有重启apache。
作者: 不帅    时间: 2015-3-25 16:01
我学习了一段时间后,我发现效果并不好(估计是我自身的问题)。因为一个人的精力总是有限的,同时学习这么多,会导致每个的学习时间都得不到保证。
作者: 第二个灵魂    时间: 2015-3-26 16:14
使用 jquery 等js框架的时候,要随时注意浏览器的更新情况,不然很容易发生框架不能使用。
作者: 若天明    时间: 2015-4-2 14:41
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
作者: 深爱那片海    时间: 2015-4-4 00:26
微软最近出的新字体“微软雅黑”,虽然是挺漂亮的,不过firefox  支持的不是很好,所以能少用还是少用的好。
作者: 飘飘悠悠    时间: 2015-4-6 21:08
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81
作者: 逍遥一派    时间: 2015-4-10 08:36
当然这种网站的会员费就几十块钱。
作者: 只想知道    时间: 2015-4-24 23:51
本文当是我的笔记啦,遇到的问题随时填充
作者: 兰色精灵    时间: 2015-5-5 01:16
要进行开发,搭建环境是首先需要做的事,windows下面我习惯把环境那个安装在C盘下面,因为我配的环境经常出现诡异事件,什么事都没做环境有的时候就不能用啦。
作者: 因胸联盟    时间: 2015-5-9 13:08
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,
作者: 活着的死人    时间: 2015-6-22 22:22
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,




欢迎光临 仓酷云 (http://www.ckuyun.com/) Powered by Discuz! X3.2