15年的时候,我写过一篇文章《略谈 vqmod for opencart 插件制做过程》,也不知道被哪些人抄袭过去了。不过无所谓了。文章梳理的思路仍是在我这里。今天对这篇文章进行进一步补充。php
file标签
若是有多个相似文件,咱们写不少个吗?其实能够没必要要,利用path和逗号解决这个问题。html
- <!-- 修改最新产品模块 -->
- <file name="catalog/view/theme/*/template/module/latest.tpl">
- <!-- 规则 -->
- </file>
- <!-- 修改热卖产品模块 -->
- <file name="catalog/view/theme/*/template/module/bestseller.tpl">
- <!-- 规则 -->
- </file>
- <!-- 改成 -->
- <file path="catalog/view/theme/*/template/module/" name="latest.tpl,bestseller.tpl">
- <!-- 规则 -->
- </file>
其中,上面的 * 表明任何文件,若是有多个模板能够这么解决。sql
operation标签
若是一个地方,搜索不到,致使整个XML不起做用怎么办呢?能够定义跳过,不过不要总使用这样的,好比你TPL搜索到了代码,可是C层或者M层搜索不到,那样会致使页面报错。因此C层和M层不建议使用跳过,而V层能够。缓存
- <file name="catalog/view/theme/*/template/product/product.tpl">
- <operation error="skip">
- <!-- 规则 -->
- </operation>
- </file>
固然了,若是你要写个注释,好比这个功能干吗的。你能够这样写:编辑器
- <file name="catalog/view/theme/*/template/product/product.tpl">
- <operation error="skip" info="添加xx功能">
- <!-- 规则 -->
- </operation>
- </file>
regex
若是你想用正则搜索怎么办呢?有时候普通搜索很难定位,其实vqmod也是支持的啦。ide
- <file name="catalog/view/theme/*/template/product/product.tpl">
- <operation error="skip" info="添加xx功能">
- <search position="replace" regex="true"><![CDATA[~<div(.*?)class="(.*?)image(.*?)"(.*?)>~]]></search>
- <!-- 规则 -->
- </operation>
- </file>
正则方面之后会写一期文章,若是你不熟悉,能够用别的替代方法,好比上面提到的文章里提到的index,也能够用下面这个。测试
offset
这个是用于搜索到的第几行,用于position的参数是after或者before的时候。能够是正数或者负数。若是是after,搜索到的行,往下数一行而后添加代码,就是1。若是你是before,而后往上数两行再添加代码在上面,就是2。this
下面搜索这段代码添加做为例子。spa
- <div class="col-sm-12">
- <label class="control-label"><?php echo $entry_rating; ?></label>
- <?php echo $entry_bad; ?>
- <input type="radio" name="rating" value="1" />
-
- <input type="radio" name="rating" value="2" />
-
- <input type="radio" name="rating" value="3" />
-
- <input type="radio" name="rating" value="4" />
-
- <input type="radio" name="rating" value="5" />
- <?php echo $entry_good; ?></div>
- </div>
用XML对这段代码进行添加代码。以下四个示例:插件
- <file name="catalog/view/theme/*/template/product/product.tpl" keep="true">
- <operation error="skip">
- <search position="after" offset="1"><![CDATA[<input type="radio" name="rating" value="1" />]]></search>
- <add><![CDATA[<b>测试1</b>]]></add>
- </operation>
- <operation error="skip">
- <search position="after" offset="-1"><![CDATA[<input type="radio" name="rating" value="2" />]]></search>
- <add><![CDATA[<b>测试2</b>]]></add>
- </operation>
- <operation error="skip">
- <search position="before" offset="1"><![CDATA[<input type="radio" name="rating" value="3" />]]></search>
- <add><![CDATA[<b>测试4</b>]]></add>
- </operation>
- <operation error="skip">
- <search position="before" offset="-1"><![CDATA[<input type="radio" name="rating" value="4" />]]></search>
- <add><![CDATA[<b>测试4</b>]]></add>
- </operation>
- </file>
你会获得下面的缓存代码:
你们从上面的图片中不难发现,before的时候offset是负数1的时候和直接用after,不用offset没区别,after的时候offset是负数1的时候和直接用before不用offset的也没区别,负数值大的时候,offset是-5,position是after等同于offset=4,position是before。因此其实offset有负数功能,可是也没太大意义。
iafter和ibefore
相比于after和before,前面加个i的区别就是,在搜索到的代码后面或者前面添加。下面给个例子:
【别问我为啥颜色不同,我有几个编辑器。】
当sql这里要添加代码的时候,好比 telephone = '" . $this->db->escape($data['telephone']) . "',
代码:
- <operation info="添加手机号">
- <search position="iafter"><![CDATA[city = '" . $this->db->escape($data['city']) . "',]]></search>
- <add><![CDATA[ telephone = '" . $this->db->escape($data['telephone']) . "',]]></add>
- </operation>
这样的话,就会在搜索到的代码后面,加入add里指定的代码。值得注意的是,平时使用其余的position时,add定义的你怎么换行都没问题,若是是iafter、ibefore和replace的时候,代码的开头最好紧挨着<add><![CDATA[ 写,为啥这样呢,由于这样SQL又是一整行,并且有时候不适合换行。也可能对后面别人开发的插件代码干扰。之后讲讲vqmod的兼容问题。
ibefore这里不举例子了,同理的。搜索的前面加,和搜索的后面加的效果。
输出:
- //iafter 的话
- city = '" . $this->db->escape($data['city']) . "', telephone = '" . $this->db->escape($data['telephone']) . "',
- //ibefore的话
- telephone = '" . $this->db->escape($data['telephone']) . "',city = '" . $this->db->escape($data['city']) . "',
PS:最近太忙了,更新频率天然降低不少了。之后多抽空更新。欢迎关注咱们公众号“SDT技术网”。