【问题标题】:Link with parameters与参数链接
【发布时间】:2017-02-19 13:22:46
【问题描述】:

我是 prestashop(1.6 版)的新手,我对链接有一些问题。 我想添加另一个带有额外参数的登录链接,以便我可以从连接页面隐藏注册部分。 所以在 nav.tpl 中,我添加了额外的参数:

$link->getPageLink('my-account', true, NULL, ['params' => 'myTest'])|escape:'html':'UTF-8'}

当我单击该链接时,它会完全消失,并且在 AuthController (initContent) Tools:getValue('params') 中返回 null。我不知道怎么弄明白。谢谢

【问题讨论】:

    标签: php model-view-controller smarty prestashop prestashop-1.6


    【解决方案1】:

    您应该使用 Smarty。

    您应该在函数 initContent 中传递文件 AuthController 的参数。

    编辑:

    $this->context->smarty->assign(array(
                    'inOrderProcess' => true,
                    'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'),
                    'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'),
                    'sl_country' => (int)$this->id_country,
                    'countries' => $countries
                ));
    

    替代方法 在同一个函数中你可以做另一个改变

    prestashop 中你可以使用 GET 和 POST 使用函数:

    $param = (int) (Tools::getValue ('myTest'));
    

    【讨论】:

    • 在 initContent 中使用 getValue() 返回 null 我还注意到单击链接(包含参数)后,链接被重新定义为我的帐户,没有参数
    【解决方案2】:

    您传递给 getPageLink 函数的数组似乎错误,请尝试以下操作:

    {$params = ['params' => 'myTest']}
    $link->getPageLink('my-account', true, NULL, $params)|escape:'html':'UTF-8'}
    

    【讨论】:

      【解决方案3】:

      这是因为当 FrontController 受到保护(例如 MyAccountController)时,用户被重定向到登录页面并且查询参数丢失。要修复它,请更改 /classes/controller/FrontController.php:

      Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
      

      到:

      Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection.'&'.$_SERVER['QUERY_STRING'] : ''));
      

      这应该会保留登录页面上的其他查询参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-29
        • 2021-08-25
        • 1970-01-01
        • 2019-04-18
        • 1970-01-01
        • 2014-01-31
        • 1970-01-01
        • 2014-02-01
        相关资源
        最近更新 更多