Home » PHP » Pimcore » How the data be save in Pimcore 5 Database

How the data be save in Pimcore 5 Database

Pimcore

There is no big deal to save data in the Pimcore Database. The below code snippet is for to check if the data is already available than it will not be save otherwise data will be save. The below code is executed on Pimcore 5.

public function defaultAction(Request $request) {       
        $data = \Pimcore\Model\DataObject\ClassName::getList();
        $data->setCondition("o_key = 'hello-world'");
        $data->load();  
        if( count($data) == 0 && $data->getObjects()[0]->getTitle() != 'Hello World'){
        $newObject->setKey(\Pimcore\File::getValidFilename('Hello World'));       
        $newObject->setParentId(1);
        $newObject->setTitle("Hello World");
        $newObject->setShortDescription("Some Text");
        $newObject->setPublished(true);
        $newObject->setStatus(true);
        $newObject->save();
        }
    }

Check Also

Top Twig Template Interview And Answer Part 1

1. How can we the path with param variables in twig template? {{ path('abc',{'test':'1'}) }} …

Leave a Reply

Your email address will not be published. Required fields are marked *