简体   繁体   中英

Modify content records in Bolt CMS

I've added a 'product' content type to my Bolt installation. I want to track and update inventory when a purchase is made, so I added an integer field 'available'. I set up a test controller to modify the record. Everything appears to work, but the update never happens. What am I missing?

<?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);
    }
}

It turns out that my code works. I was checking the result by reloading the back-end edit form, which had apparently cached its data, so I didn't see the value changing.

The same thing happens if I load the edit form in two browser tabs and update one, then refresh the other, so it looks like this is the best I can do.

I have faced a similar problem. Either the updated codes didn't show up or the result in the output is unchanged. Figured though this happened due to setting debug: false in the config.yml file. When debug is true your in bolt-data/app/ all cache files increases but this thing get sorted. In production it is suggested that to keep debug: false but this problem checks-in too, hence the way you are dealing with it comes out to be the easiest way out without changing the configuration much.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM