【问题标题】:Reditrect Home page to Product page Opencart 3.0.3.6 or 3.0.3.7 using OCMOD xml使用 OCMOD xml 将主页重定向到产品页面 Opencart 3.0.3.6 或 3.0.3.7
【发布时间】:2021-05-17 23:39:00
【问题描述】:

我正在尝试在 opencart 中重定向主页目录/控制器/common/home.php。 在 php 文件中,这一行之后 public function index() { 和这一行之前 $this->config->get('config_meta_title'));当我添加 $this->response->redirect($this->url->link('product/product', 'product_id=50'));当用户访问 opencart 主页时,它会重定向并工作。我需要创建 OCMOD 文件来实现相同的目的,而无需修改此 php 文件中的核心代码。我也不想使用 htaccess 重定向。我尝试了下面的代码但没有工作。我对 XML 或 PHP 的了解并不多。因此请帮忙。我尝试的 OCMOD 代码如下:

<name>Product page as home page</name>
<id>Product page as home page</id>
<version>1.0.0</version>
<code>Product page as home page</code>
<author>test</author>
<link>#</link>  

<file path="catalog/controller/common/home.php">
    
             <operation>
        <search><![CDATA[if (isset($this->document->setTitle($this->config->get('config_meta_title'));'])) {]]></search>
        <add position="before"><![CDATA[
    $this->response->redirect($this->url->link('product/product', 'product_id=50'));
        ]]></add>
    </operation>
</file>

请帮忙。感谢致敬 VSR

【问题讨论】:

    标签: php xml ocmod


    【解决方案1】:

    那里不是 ocmod。这是vqmod。此处为 OCMOD:

    <?xml version="1.0" encoding="UTF-8"?>
    <modification>
    <name>Product page as home page</name>
    <version>1.0.0</version>
    <code>Product page as home page</code>
    <author>test</author>
    <link>#</link>  
    
    <file path="catalog/controller/common/home.php">
        
        <operation>
            <search><![CDATA[if (isset($this->document->setTitle($this->config->get('config_meta_title'));'])) {]]></search>
            <add position="before"><![CDATA[
        $this->response->redirect($this->url->link('product/product', 'product_id=50'));
            ]]></add>
        </operation>
    </file>
    </modification>
    

    并仔细检查 ocmod 搜索标签中的字符串...if (isset($this-&gt;document-&gt;setTitle($this-&gt;config-&gt;get('config_meta_title'));'])) { 是否正确?似乎字符串不正确。

    编辑关于您的评论:

     <?xml version="1.0" encoding="UTF-8"?>
        <modification>
        <name>Product page as home page</name>
        <version>1.0.0</version>
        <code>Product page as home page</code>
        <author>test</author>
        <link>#</link>  
        
        <file path="catalog/controller/common/home.php">
        
            <operation>
                <search><![CDATA[public function index() {]]></search>
                <add position="after"><![CDATA[
            $this->response->redirect($this->url->link('product/product', 'product_id=50'));
                ]]></add>
            </operation>
        </file>
        </modification>
    

    【讨论】:

    • 感谢 K.B。我试过你修改过的代码,还是不行。我试图删除上面代码中的“{”,但没有用。请参阅下面的 home.php 代码: public function index() { $this->document->setTitle($this->config->get(' config_meta_title')); 这个代码:$this->response->redirect($this->url->link('product/product', 'product_id=50')); 必须动态放置在公共函数index()之后{ 之前 $this->document->setTitle($this->config->get('config_meta_title'));
    • 我已根据您的评论进行了编辑。请立即检查。
    • 嗨,K.B.我试过你编辑的代码。但是主页没有重定向。我之前也尝试过的相同代码。它不起作用。如何动态插入 $this->response->redirect($this->url->link('product/product', 'product_id=50'));在那个特定位置的 home.php 中使用 OCMOD?当该代码手动添加到 home.php 中时,它会正确重定向。但不能用 OCMOD 做到这一点。如果您能进一步提供帮助,那就太好了。谢谢
    • 看来我也犯了一个错误。立即尝试“已编辑”。我再次编辑了我的代码。
    • 嗨,K.B 现在完美运行。优秀。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2018-10-07
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多