VQMOD替换不适用于多行搜索

seo*_*wer 2 php opencart vqmod

opencart中有一个函数,我需要替换如下:

protected function validateDelete() {
        if (!$this->user->hasPermission('modify', 'catalog/download')) {
            $this->error['warning'] = $this->language->get('error_permission');
Run Code Online (Sandbox Code Playgroud)

应该:

protected function validateDelete() {
        if (!$this->user->hasPermission('delete', 'catalog/download')) {
            $this->error['warning'] = $this->language->get('error_permission_delete');
Run Code Online (Sandbox Code Playgroud)

我试过了:

<search position="replace"><![CDATA[
            protected function validateDelete() {
                if (!$this->user->hasPermission('modify',]]></search>
            <add><![CDATA[
            protected function validateDelete() {
                if (!$this->user->hasPermission('delete',
            ]]></add>
Run Code Online (Sandbox Code Playgroud)

但它不起作用.第三行出现在多个位置,因此无法单行替换.

请帮忙

San*_*r V 7

无法在vqmod中进行多行搜索.所以你需要使用vqmod index属性.如果"搜索"字符串为"hello"且文件中有5个"hello",但您只想替换第1个和第3个,请使用Index:1,3.

所以更改你的vqmod代码如下:

<operation>
    <search position="replace" index="3"><![CDATA[if (!$this->user->hasPermission('modify', 'catalog/download')) {]]></search>
    <add><![CDATA[
        if (!$this->user->hasPermission('delete', 'catalog/download')) {
    ]]></add>
</operation>
<operation>
    <search position="replace" index="3"><![CDATA[$this->error['warning'] = $this->language->get('error_permission');]]></search>
    <add><![CDATA[
        $this->error['warning'] = $this->language->get('error_permission_delete');
    ]]></add>
</operation>
Run Code Online (Sandbox Code Playgroud)

不要忘记更新index值.

参考链接:https://sankartypo3.wordpress.com/2013/11/25/opencart-vqmod-tutorial/,http : //code.google.com/p/vqmod/wiki/Scripting

祝你今天愉快 !!