PHP之Smarty学习

2.建立templates,templates_c,configs,cache目录

退出Redis命令行

[root@localhost redis-3.0.7]# src/redis-cli
127.0.0.1:6379> quit
[root@localhost redis-3.0.7]# 

6.打开index.php即可以测试Smarty了.

布XShell前之预备

开辟VM,启动CentOSMini。CentOSMini启动之后上Terminal。

[root@localhost ~]# ip addr

输入指令ip addr ,回车查看inet地址。

切换回Windows,打开CMD,输入指令ipconfig,回车查看IPv4地址。

>ipconfig

比对少数个ip地址是否当同一IP段,即IP地址形式要{1}.{2}.{3}.{4},比对1,2,3有的是不是一律,相同便为同一IP段,此为XShell连通虚拟机安装的CentOSMini的前提。

3.建测试页面:index.php

测试Redis

每当XShell,打开一个新的顶点标签

[root@localhost ~]# ls
anaconda-ks.cfg  redis-3.0.7  redis-3.0.7.tar.gz
[root@localhost ~]# cd redis-3.0.7
[root@localhost redis-3.0.7]# src/redis-cli
127.0.0.1:6379> KEYS *
1) "user:1"
2) "test"
3) "Manager"
4) "name"
127.0.0.1:6379> 

*/
session_start();//开启session
include “libs/Smarty.class.php”;
define(‘__SITE_ROOT’, ‘E:/PHPnow-1.5.1/vhosts/xxh.com’); //
最终没斜线
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . “/templates/”;
$tpl->compile_dir = __SITE_ROOT . “/templates_c/”;
$tpl->config_dir = __SITE_ROOT . “/configs/”;
$tpl->cache_dir = __SITE_ROOT . “/cache/”;
$tpl->left_delimiter = ‘<{‘;
$tpl->right_delimiter = ‘}>’;
?>

启动Redis

[root@localhost redis-3.0.7]# src/redis-server
14891:C 27 Apr 13:10:08.132 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
14891:M 27 Apr 13:10:08.132 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 14891
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

14891:M 27 Apr 13:10:08.134 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
14891:M 27 Apr 13:10:08.134 # Server started, Redis version 3.0.7
14891:M 27 Apr 13:10:08.134 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
14891:M 27 Apr 13:10:08.134 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
14891:M 27 Apr 13:10:08.135 * DB loaded from disk: 0.001 seconds
14891:M 27 Apr 13:10:08.135 * The server is now ready to accept connections on port 6379

<html>
  <head>
  <meta http-equiv=”Content-Type” content=”text/html;
charset=gb2312″>
  <title><{$title}></title>
  </head>
  <body>
  <{$content}>
  </body>
  </html>

下载和安装Redis

Redis安装包网址
新型的安装包为redis-3.0.7.tar.gz

[root@localhost ~]#wget http://download.redis.io/releases/redis-3.0.7.tar.gz
[root@localhost ~]#tar zxvf redis-3.0.7.tar.gz
[root@localhost ~]# cd redis-3.0.7
[root@localhost redis-3.0.7]# make MALLOC=libc

/*下那加设未加会报告错误:

安转Redis

以下配置,默认用户还无成功,即便已就,再度实施不谋面暴发影响。

非通晓干什么

加载插件gcc

[root@localhost ~]# yum gcc

4.在templates下创建模板文件index.htm

运XShell远程连接CentOSMini

点击download下载XShell5.0。
下载后安装。配置XShell。

$tpl->assign(“title”, “测试用的网页标题”);
$tpl->assign(“content”, “测试用的网页内容”);
// 下边两履啊足以为此当下行代替
// $tpl->assign(array(“title” => “测试用的网页标题”, “content”
=> “测试用底网页内容”));
$tpl->display(‘Index.htm’);
?>

配置XShell

开辟XShell,点击对话->新建,弹窗如图
图片 1
输入名称,自己随便起名,那里我自从名CentOSMini。
长机框输入,查询到的CentOSMini的inet地址。
端口号,默认22,假诺端口被挤占可能造成连日退步。
点击用户身份验证,输入CentOSMini的账户与密码
图片 2
布置好,尝试连接。尽管持续失退步,请自行排查原因。
默认连接成功,开头安装Redis。

参考网络上的资料,使用Smarty能够省略的测试:

加载插件wget

[root@localhost ~]# yum wget

//$tpl在main.php中定义

关闭Redis

Redis命令行下

[root@localhost redis-3.0.7]# src/redis-cli
127.0.0.1:6379> shutdown

非Redis命令行下

[root@localhost redis-3.0.7]# src/redis-cli shutdown

<?php
require “main.php”;

1.解压Smarty到网站目录下,比如起名libs.

Notice: Undefined variable: _SESSION in
E:\PHPnow-1.5.1\vhosts\xxh.com\libs\Smarty.class.php on line
585

5.建立main.php

<?php

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图