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

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

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

file标签

若是有多个相似文件,咱们写不少个吗?其实能够没必要要,利用path和逗号解决这个问题。html

 
  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>

其中,上面的 * 表明任何文件,若是有多个模板能够这么解决。sql

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也是支持的啦。ide

 
  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。this

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

 
  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技术网”。

相关文章
相关标签/搜索