代码之家  ›  专栏  ›  技术社区  ›  Enthu

在同一个类文件中的钩子之间传递变量

  •  0
  • Enthu  · 技术社区  · 7 年前

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

    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. 可能是个小问题,但我现在还没弄清楚。

    2 回复  |  直到 7 年前
        1
  •  1
  •   TheDrot    7 年前

    您应该只存储对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');
    }
    
        2
  •  0
  •   andriusain    7 年前

    你忘了用 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');
    }
    
    推荐文章