【问题标题】:Silverstripe 3 doPublish in ControllerSilverstripe 3 doPublish 在控制器中
【发布时间】:2012-10-03 10:24:14
【问题描述】:

在一个旧的 silverstripe 安装 (2.4) 中,我有一个小计数器功能,基本上看起来像这样:

class Page_Controller extends ContentController {
  public function countUp(){ 
    $this->Counter = $this->Counter+1;
    $this->writeToStage('Stage');
    $this->publish("Stage", "Live");
  }
}

我想把它移到 SS 3。 不知何故,它不再起作用了,计数器属性永远不会在数据库中更新。 有人知道为什么吗?

亲切的问候, 弗洛里安

【问题讨论】:

    标签: content-management-system silverstripe


    【解决方案1】:

    1 - 该方法应该在 Page 类(模型)上,而不是控制器上。然后你可以调用 $this->data()->countUp();来自 Page_Controller 类。

    2 - 你需要 $this->write();之前 $this->writeToStage('Stage');

    【讨论】:

    • 还有一个奇怪的事情......计数器在Page_Live表中更新,但在Page中没有更新。我现在以不同方式解决的计数器问题...我将计数保存在每个页面的单独 DataObject 中,导致更新和发布页面总是在 Page_versions 中创建一个新版本
    • 这仍然很奇怪:计数器在 Page_Live 表中更新,但在 Page 中没有更新(我认为这是 Stage)。如果我在 CMS 中编辑页面,然后显示表页面的计数器值 (0)。然后发布用 0 覆盖 Page_Live 计数器。我看到函数 $this->writeToStage('Stage');正在更新页表。但是如果添加了 $this->write();在此之前,仅更新 Page_Live。所有 3 个函数(write、writeToStage、publish)也是如此。功能错误?
    • 您的writeToStage() / publish() 代码是正确的。但是该方法确实应该在Page 类上,而不是Page_Controller
    • 谢谢,最后我以不同的方式解决了它。我创建了一个“计数器” - 与每个页面相关的数据对象。所以在更新计数时,没有创建新版本的页面(因为对于页面当然激活了版本控制)。
    猜你喜欢
    • 2012-06-14
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多