php - VQMOD 替换不适用于多行搜索

标签 php opencart vqmod

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

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

应该是:

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

我试过:

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

但它不起作用。第三行出现在多个位置,不能单行替换。

请帮忙

最佳答案

在 vqmod 中不能进行多行搜索。所以你需要使用 vqmod index 属性。如果“搜索”字符串是 'hello' 并且文件中有 5 个 'hello's,但您只想替换第 1 个和第 3 个,请使用索引: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>

不要忘记更新 index 值。

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

祝你有美好的一天!!

关于php - VQMOD 替换不适用于多行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23486122/

相关文章:

php - php 是否存在 `pry` 等价物?

PHP 按钮,在 php 文件中处理,然后重定向到另一个页面

php - 在哪里可以找到有关扩展 Opencart 的良好文档

php - 为什么 OpenCart 3 中的图像无法通过管理面板加载?

mysql - 如何通过VQMOD创建新的数据库表(如果不存在)

php - Magento : Getting Product Collection Sorted by minimum price

php - 什么情况下会出现PDO :execute() return false?

php - 在 opencart 数据库中添加新字段

php - 在 Opencart admin 'Order Info' 页面上添加自定义字段