zoukankan      html  css  js  c++  java
  • Nginx.PHP配置Smarty

    1. 下载http://smarty.net;
    2. 解压 -> 将 libs 文件夹重命名 smartyLibs -> 放置在自己服务器的 usr/local/lib/ 中 (/usr/local/lib/smartyLibs);
    3. 在网站目录,如 site_A 中 创建 4 个必须文件夹 templates、templates_c、configs、cache
      //设置权限
      chown nginx:nginx "4个目录";
      chmod 770 "4个目录";
    4. 在网站目录中创建 smarty.ini.php 配置文件(smarty基本配置信息),内容如下
      <?php
      define('SMARTY_DIR','/usr/local/lib/smartyLibs/');//定义lib路径
      require_once(SMARTY_DIR.'Smarty.class.php');//引用Smarty库
      $smarty=new Smarty();//创建Smarty
      
      define('SMARTY_SITE','/var/www/html/site_A/');//定义网站路径
      $smarty->setTemplateDir(SMARTY_SITE.'templates');
      $smarty->setCompileDir(SMARTY_SITE.'templates_c');
      $smarty->setConfigDir(SMARTY_SITE.'configs');
      $smarty->setCacheDir(SMARTY_SITE.'cache');
      $smarty->left_delimiter='{{';
      $smarty->right_delimiter='}}';
      
      $smarty->caching=false;//是否使用缓存
      
      //$smarty->testInstall();//调试用,显示4个目录可读写状态
      ?>
    5. 创建网站页面文件 index.php
      <?php
      include('./smarty.ini.php');//引用smarty.ini.php配置文件
      $name='YangGe123';//自定义变量
      $smarty->assign('name',$name);//将变量赋予smarty值'name'
      $smarty->display('index.tpl');//在templates中引用对应的模板
      ?>
    6. 在Templates中创建网站对应的模板
      <html>
          <head></head>
          <body>
              <h1>{$name}</h1>
          </body>
      </html>

    扩展知识:

    调试php,让服务器显示php错误信息:

    修改php.ini文件,将 display_error = off 改为 on

    重启php服务

    service php-fpm restart

  • 相关阅读:
    Spring Boot----freemark使用
    vue----解决跨域问题
    CSS----精灵图
    Spring MVC----文件上传
    Mybatis----Mybatis使用
    Django url引用异常
    Django ORM异常
    django sqlite3 报错问题
    爬虫 requests的超时和重试
    python 异常 NameError: name 'ModuleNotFoundError' is not defined
  • 原文地址:https://www.cnblogs.com/enone/p/4118857.html
Copyright © 2011-2022 走看看