【问题标题】:Show $params array('{item}' =>…)显示 $params array('{item}' =>…)
【发布时间】:2015-09-17 12:09:29
【问题描述】:

需要帮助。在 Prestashop 中的 PaymentModule.php 中有此代码:

$params = array(
    '{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false),
    '{voucher_num}' => $voucher->code,
    '{firstname}' => $this->context->customer->firstname,
    '{lastname}' => $this->context->customer->lastname,
    '{id_order}' => $order->reference,
    '{order_name}' => $order->getUniqReference()
);

我使用$params['firstname'] 向客户展示firstname,但一无所获。我在/modules/bankwire/bankwire.php中插入$params['firstname']

请告诉我哪里出错了?

谢谢

【问题讨论】:

  • 从数组键中删除{},即$params = array( 'firstname' => ...,)
  • Kenney : 为什么你确定键是错的?这个问题被标记为smartyprestashop-1.6,所以它很可能是一个模板,删除花括号可能会破坏它。
  • 感谢您编辑我的问题。抱歉,我是新来的,不太了解格式
  • 你在哪里定义 $params 数组,你想在哪里使用条目?要么该值是真正的空,因为没有输入名字,要么涉及某种转换,例如是否存在将 $param 元素绑定到视图模板的机制?

标签: php arrays oop smarty prestashop-1.6


【解决方案1】:

在您的数组中,您有一个 {firstname} 键,但没有 firstname 键。

如果你想获得价值,你应该使用:$params['{firstname}']

【讨论】:

  • 谢谢,但我试过这种方式 - $params['{firstname}'] 也没有。它显示得很好的简单字符串,但不是数组项。你能告诉我其他的解决方案吗?
  • 试试:print_r($params) 告诉我们你得到了什么输出
【解决方案2】:

试试

$params = array(
    'voucher_amount' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false),
    'voucher_num' => $voucher->code,
    'firstname' => $this->context->customer->firstname,
    'lastname' => $this->context->customer->lastname,
    'id_order' => $order->reference,
    'order_name' => $order->getUniqReference()
);

或者如果volkerk是对的,试试

$params['{firstname}'] 

【讨论】:

  • 你为什么确定键是错的?这个问题用smartyprestashop-1.6标记,所以它很可能是一个模板,去掉花括号可能会破坏它。
【解决方案3】:

邮件模板有变量,就是assoc数组,供访问使用

$params['{voucher_amount}']

【讨论】:

    猜你喜欢
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 2014-09-13
    • 1970-01-01
    • 2020-05-07
    • 2022-01-18
    • 1970-01-01
    相关资源
    最近更新 更多