在同一 Class 文件中的挂钩之间传递变量

Passing Variable Between Hooks in Same Class File

我正在尝试从一个操作挂钩中检索一个值以显示在管理页面中。

public function hookActionProductCancel($params)
{
    $this->response = "response";
}
public function hookDisplayAdminOrder($params) {
    $this->context->smarty->assign('response', $this->response);
    return $this->display(__FILE__, 'views/templates/admin/response.tpl');
}

我没有在 response.tpl 中收到值 "response"。可能是个小问题,但我现在没弄好。

非常感谢任何指导。谢谢。

您忘记使用 this

public function hookActionProductCancel($params)
{
    ..... codes .....
    $this->response = "response";
}

public function hookDisplayAdminOrder($params) 
{
    $this->context->smarty->assign('response', $this->response);
    return $this->display(__FILE__, 'views/templates/admin/response.tpl');
}

您应该只存储对 cookie 的响应并在显示之前清除它。

public function hookActionProductCancel($params)
{
    // code
    $this->context->cookie->mymodule_response = "response";
    $this->context->cookie->write();
}
public function hookDisplayAdminOrder($params) 
{
    // if no response stored in cookie do nothing
    if (!$this->context->cookie->mymodule_response) {
        return false;           
    }

    // assign response from cookie to smarty then clear response from cookie
    $this->context->smarty->assign('response', $this->context->cookie->mymodule_response);
    unset($this->context->cookie->mymodule_response);

    return $this->display(__FILE__, 'views/templates/admin/response.tpl');
}