修改Bolt CMS中的内容记录

问题描述 投票:0回答:1

我在Bolt安装中添加了“产品”内容类型。我想在购买时跟踪和更新库存,因此我添加了一个整数字段'available'。我设置了一个测试控制器来修改记录。一切似乎都有效,但更新永远不会发生。我错过了什么?

<?php
namespace Bundle\Site;
class CartController extends \Bolt\Controller\Base
{
    public function addRoutes(\Silex\ControllerCollection $c)
    {
        $c->match('/test-save', [$this,'testSave']);
        return $c;
    }
    public function testSave()
    {
        $result=false;
        $repo = $this->app['storage']->getRepository('products');
        $content = $repo->find(1);
        //Error log output confirms that this is the correct record
        error_log(get_class($this).'::'.__FUNCTION__.': '.json_encode($content));
        $content->set('available',15);
        $content->setDatechanged('now');
        $result=$repo->save($content); //returns 1
        return new \Symfony\Component\HttpFoundation\Response(json_encode($result), \Symfony\Component\HttpFoundation\Response::HTTP_OK);
    }
}
bolt-cms
1个回答
0
投票

事实证明我的代码是有效的。我通过重新加载后端编辑表单检查结果,后者显然已缓存其数据,因此我没有看到值的变化。

如果我在两个浏览器选项卡中加载编辑表单并更新一个,然后刷新另一个,就会发生同样的事情,所以看起来这是我能做的最好的事情。

© www.soinside.com 2019 - 2024. All rights reserved.