【问题标题】:How to Set Category Page as Home Page in Prestashop如何在 Prestashop 中将类别页面设置为主页
【发布时间】:2013-10-01 12:14:48
【问题描述】:

我将http://example.com/index.php 作为我的主页。 我的分类页面网址是http://example.com/index.php?id_category=10&controller=category

现在,我需要将我的主页重定向到类别页面。 我尝试了 Preferences > SEO & URL's > Set Shop URL > Base URI 如 index.php?id_category=10&controller=category

现在,页面正在重定向到我的类别 URL,但页面没有打开。 URL 是这样显示的 http://example.com/index.php?id_category=10&controller=category/index.php?

【问题讨论】:

    标签: php prestashop


    【解决方案1】:

    你做错了。请按照以下步骤操作:

    A) 简单但不推荐的方式:

    1) 打开 Controllers/IndexController.php

    2) 修改函数initContent如下:

    public function initContent()
    {
    
       parent::initContent();
       Tools::redirect('index.php?id_category=10&controller=category');
       $this->context->smarty->assign('HOOK_HOME', Hook::exec('displayHome'));
       $this->setTemplate(_PS_THEME_DIR_.'index.tpl');
    
    }
    

    B) 推荐方式:

    1) 复制 Controllers/IndexController.php 到 override/Controllers/ 文件夹 2)打开复制的文件并编辑如下:

    class IndexController extends IndexControllerCore 
    {
    
        public function initContent()
        {
           Tools::redirect('index.php?id_category=10&controller=category');
    
        }
    }
    

    3) 保存文件并转到缓存文件夹。查找 class_index.php ,如果存在则将其删除。然后检查网站是否运行良好。

    注意事项:

    1) 上面的代码是为了给你一个想法,它可能会也可能不会起作用。请根据您的需要进行调整。

    2) 在最新版本的 Prestashop 中,所有类都在 class_index.php 文件中进行索引。因此,如果您对控制器或类进行了任何覆盖,则在您删除该文件之前它可能无法工作。当向服务器发出新请求时,PS 会自动为您重新生成该文件。

    希望这会有所帮助。

    【讨论】:

    • 这种方式对我有用,但我怎样才能在不更改 url 的情况下做到这一点?
    【解决方案2】:

    这是我的方式:

    1. 创建文件 override/controllers/front/IndexController.php
    2. 写作:
    类 IndexControllerCore 扩展 FrontController { 公共函数 initContent() { 工具::redirect('index.php?id_category=3&controller=category'); } }
    1. 保存
    2. 删除文件缓存/class_index.php
    3. 利润!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多