zoukankan      html  css  js  c++  java
  • ecshop的smarty库还原成smarty原生库方法

    写过ecshop模板的人都晓得,他们是用所谓的dwt的文件来嵌套lbi文件进行模板的彼此调用。在咱们调取数据的时分,ecshop的默许模板只提供给咱们几个简略的句子进行调用,那么有没有办法能够把这个精简的cls_template类添加其他的句子呢?

    首要断定版别:ECShop v2.7.3

    通过近一天对ecshop程序的研讨,发现这个所谓的cls_template类,其实是一个精简版的smarty,而且值得幸亏的是,这个cls_template类没有包括其他的文件。那么咱们完全能够将官方smarty直接拿来用。断定了这一点,剩余的就是看ECShop在哪里运用这个cls_template类了。

    翻开index.php,咱们发现他里边有这样一句话:

    1. require(dirname(__FILE__).'/includes/init.php');

    所以咱们找到这个文件,找到创立的那个cls_template类,代码如下:

    1. require(ROOT_PATH .'includes/cls_template.php');
    2. $smarty =new cls_template;

    这里发现他们创立了一个smarty的一个目标,其实咱们写的模板中一切能用的标签都是用这个的。

    我这里不说废话了,直接给办法了。

    仿制一份init.php 为 init_x.php ,在根目录的 index.php 中,将:

    1. require(dirname(__FILE__).'/includes/init.php');

    改为:

    1. require(dirname(__FILE__).'/includes/init_x.php');

    即可。原因是还有其他地方运用了init.php,直接修正的话,会形成不行预知的成果。

    如今去官方下载一个smarty模板,这里用的是2.6的版别(3.1的版别试过,有错。估量ecshop其时用的是2.6兼容的,别问我为啥。),放在include的文件夹里,而且在init_x.php中包括当时的原生smarty类而且用Smarty类交换之前的cls_template类,代码如下:

    1. /* 获得当时ecshop地点的根目录 */
    2. define('ROOT_PATH', str_replace('includes/init_x.php','', str_replace('\','/', __FILE__)));
    1. /* 创立 Smarty 目标。*/
    2. require(ROOT_PATH .'includes/Smarty-2.6.27/libs/Smarty.class.php');
    3. $smarty =newSmarty;
    4.  
    5. $smarty->cache_lifetime = $_CFG['cache_time'];
    6. $smarty->template_dir = ROOT_PATH .'themes/'. $_CFG['template'];
    7. $smarty->cache_dir = ROOT_PATH .'temp/caches';
    8. $smarty->compile_dir = ROOT_PATH .'temp/compiled';

    这里注重途径和类名的修正。还有就是细心查看smarty类需求的那几个变量和路近能否都存在。

    持续往下查看:

    1. if((DEBUG_MODE &2)==2)
    2. {
    3. $smarty->direct_output =true;//我记住这个变量smarty如同没有
    4. $smarty->force_compile =true;
    5. }
    6. else
    7. {
    8. $smarty->direct_output =false;//
    9. $smarty->force_compile =false;
    10. }

    看这一段,查看smarty类里能否存在这几个变量,没有就删掉。

    断定无误后,能够回到根目录的index.php文件上了。

    之前,咱们将init.php 换成了init_x.php,这仅仅第一步。下面咱们要持续修正模板,将一切的dwt文件换成tpl文件(回忆中是两处)。

    如今进入themes文件夹,将index.dwt文件修正为index.tpl文件。

    如今咱们来翻开debug,看看能不能进行smarty调试,并运用其他的smarty标签了。(这里阐明一下,smarty文件夹需求有可运转的权限。)

    还记住刚刚你屏蔽的那两行smarty不存在的变量么?那个是调试。咱们细心对照发现,2.6的smarty调试的变量名称为debuging。

    咱们将方才:

    1. $smarty->direct_output =false;

    中的direct_output,修正为debuging,而且改为true就能够弹出smarty官方的调试窗口了

  • 相关阅读:
    Python--BeautifulSoup4丶Tag丶Xpath丶requests+re的基础学习及使用
    c#字符串字面量
    vim操作
    序列的方法
    python数值类型与序列类型
    Linux操作学习笔记1
    Jav的10个面向对象设计原则
    JAVA面向对象基础
    二进制 八进制 十六进制
    using 的故事
  • 原文地址:https://www.cnblogs.com/AloneSword/p/3513641.html
Copyright © 2011-2022 走看看