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

如何在OctoberCMS中附加组件的响应头?

  •  0
  • kanji  · 技术社区  · 6 年前

    如果我是实例化响应对象的人,我可以调用 header 方法如下所述 October documentation

    但是,要从组件执行此操作,我需要从组件的onRun方法返回response对象,它将终止 the layout lifecycle

    1 回复  |  直到 6 年前
        1
  •  0
  •   kanji    6 年前

    我找到了一个似乎是正确的方法。

    钩住 cms.page.display

        public function myComponentMethod()
        {
            Event::listen('cms.page.display', function ($controller, $url, $page, $result) {
                $headers = [
                    // Headers you want to set
                    'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0',
                    'Pragma' => 'no-cache',
                ];
                return Response::make($result, $controller->getStatusCode(), $headers);
            });
        }
    

    请看 here 了解10月份事件处理的细节。