zoukankan      html  css  js  c++  java
  • vqmod for opencart插件制作进阶与技巧

    FROM: http://www.sdtclass.com/4799.html

    15年的时候,我写过一篇文章《略谈 vqmod for opencart 插件制作过程》,也不知道被哪些人抄袭过去了。不过无所谓了。文章梳理的思路还是在我这里。今天对这篇文章进行进一步补充。

    file标签

    如果有多个类似文件,我们写很多个吗?其实可以不必要,利用path和逗号解决这个问题。

     
    1. <!-- 修改最新产品模块 -->
    2. <file name="catalog/view/theme/*/template/module/latest.tpl">
    3. <!-- 规则 -->
    4. </file>
    5. <!-- 修改热卖产品模块 -->
    6. <file name="catalog/view/theme/*/template/module/bestseller.tpl">
    7. <!-- 规则 -->
    8. </file>
    9. <!-- 改为 -->
    10. <file path="catalog/view/theme/*/template/module/" name="latest.tpl,bestseller.tpl">
    11. <!-- 规则 -->
    12. </file>

    其中,上面的 * 代表任何文件,如果有多个模板可以这么解决。

    operation标签

    如果一个地方,搜索不到,导致整个XML不起作用怎么办呢?可以定义跳过,不过不要总使用这样的,比如你TPL搜索到了代码,但是C层或者M层搜索不到,那样会导致页面报错。所以C层和M层不建议使用跳过,而V层可以。

     
    1. <file name="catalog/view/theme/*/template/product/product.tpl">
    2.     <operation error="skip">
    3.         <!-- 规则 -->
    4.     </operation>
    5. </file>

    当然了,如果你要写个注释,比如这个功能干嘛的。你可以这样写:

     
    1. <file name="catalog/view/theme/*/template/product/product.tpl">
    2.     <operation error="skip" info="添加xx功能">
    3.         <!-- 规则 -->
    4.     </operation>
    5. </file>

    regex

    如果你想用正则搜索怎么办呢?有时候普通搜索很难定位,其实vqmod也是支持的啦。

     
    1. <file name="catalog/view/theme/*/template/product/product.tpl">
    2.     <operation error="skip" info="添加xx功能">
    3.         <search position="replace" regex="true"><![CDATA[~<div(.*?)class="(.*?)image(.*?)"(.*?)>~]]></search>
    4.         <!-- 规则 -->
    5.     </operation>
    6. </file>

    正则方面以后会写一期文章,如果你不熟悉,可以用别的替代方法,比如上面提到的文章里提到的index,也可以用下面这个。

    offset

    这个是用于搜索到的第几行,用于position的参数是after或者before的时候。可以是正数或者负数。如果是after,搜索到的行,往下数一行然后添加代码,就是1。如果你是before,然后往上数两行再添加代码在上面,就是2。

    下面搜索这段代码添加作为例子。

     
    1. <div class="col-sm-12">
    2.     <label class="control-label"><?php echo $entry_rating; ?></label>
    3.     &nbsp;&nbsp;&nbsp; <?php echo $entry_bad; ?>&nbsp;
    4.     <input type="radio" name="rating" value="1" />
    5.     &nbsp;
    6.     <input type="radio" name="rating" value="2" />
    7.     &nbsp;
    8.     <input type="radio" name="rating" value="3" />
    9.     &nbsp;
    10.     <input type="radio" name="rating" value="4" />
    11.     &nbsp;
    12.     <input type="radio" name="rating" value="5" />
    13.      &nbsp;<?php echo $entry_good; ?></div>
    14. </div>

    用XML对这段代码进行添加代码。如下四个示例:

     
    1. <file name="catalog/view/theme/*/template/product/product.tpl" keep="true">
    2.     <operation error="skip">
    3.         <search position="after" offset="1"><![CDATA[<input type="radio" name="rating" value="1" />]]></search>
    4.         <add><![CDATA[<b>测试1</b>]]></add>
    5.     </operation>
    6.     <operation error="skip">
    7.         <search position="after" offset="-1"><![CDATA[<input type="radio" name="rating" value="2" />]]></search>
    8.         <add><![CDATA[<b>测试2</b>]]></add>
    9.     </operation>
    10.     <operation error="skip">
    11.         <search position="before" offset="1"><![CDATA[<input type="radio" name="rating" value="3" />]]></search>
    12.         <add><![CDATA[<b>测试4</b>]]></add>
    13.     </operation>
    14.     <operation error="skip">
    15.         <search position="before" offset="-1"><![CDATA[<input type="radio" name="rating" value="4" />]]></search>
    16.         <add><![CDATA[<b>测试4</b>]]></add>
    17.     </operation>
    18. </file>

    你会得到下面的缓存代码:

    vqmod for opencart插件制作进阶与技巧

    大家从上面的图片中不难发现,before的时候offset是负数1的时候和直接用after,不用offset没区别,after的时候offset是负数1的时候和直接用before不用offset的也没区别,负数值大的时候,offset是-5,position是after等同于offset=4,position是before。所以其实offset有负数功能,但是也没太大意义。

    iafter和ibefore

    相比于after和before,前面加个i的区别就是,在搜索到的代码后面或者前面添加。下面给个例子:

    vqmod for opencart插件制作进阶与技巧

    【别问我为啥颜色不一样,我有几个编辑器。】

    当sql这里要添加代码的时候,比如 telephone = '" . $this->db->escape($data['telephone']) . "',

    代码:

     
    1. <operation info="添加手机号">
    2.     <search position="iafter"><![CDATA[city = '" . $this->db->escape($data['city']) . "',]]></search>
    3.     <add><![CDATA[ telephone = '" . $this->db->escape($data['telephone']) . "',]]></add>
    4. </operation>

    这样的话,就会在搜索到的代码后面,加入add里指定的代码。值得注意的是,平时使用其他的position时,add定义的你怎么换行都没问题,如果是iafter、ibefore和replace的时候,代码的开头最好紧挨着<add><![CDATA[ 写,为啥这样呢,因为这样SQL又是一整行,而且有时候不适合换行。也可能对后面别人开发的插件代码干扰。以后讲讲vqmod的兼容问题。

    ibefore这里不举例子了,同理的。搜索的前面加,和搜索的后面加的效果。

    输出:

     
    1. //iafter 的话
    2. city = '" . $this->db->escape($data['city']) . "', telephone = '" . $this->db->escape($data['telephone']) . "',
    3. //ibefore的话
    4.  telephone = '" . $this->db->escape($data['telephone']) . "',city = '" . $this->db->escape($data['city']) . "',

    PS:最近太忙了,更新频率自然下降很多了。以后多抽空更新。欢迎关注我们公众号“SDT技术网”。

  • 相关阅读:
    关于MAC下重置MYSQL密码
    MAC下配置PHPStorm环境
    Java中从控制台输入数据的几种常用方法
    IDEA 指定入口class
    Python中的除法
    Python 学习笔记
    SQLiteDatabase中query、insert、update、delete方法参数说明
    listview与sqlite数据绑定
    java中HashMap详解
    只要有信心,人永远不会挫败
  • 原文地址:https://www.cnblogs.com/carbon3/p/7921583.html
Copyright © 2011-2022 走看看