Leo T Abraham
Leo T Abraham

Reputation: 2437

How to move an asset from one folder to another in Pimcore using PHP API

I'm able to upload assets using PHP API in pimcore using the documentation

$newAsset = new Pimcore\Model\Asset();
$newAsset->setFilename("myAsset.png");
$newAsset->setData(file_get_contents("some-file.png"));
$newAsset->setParent(Pimcore\Model\Asset::getByPath("/"));
$newAsset->save();

What if I want to move that asset from current folder to another using PHP API?

I have tried with the following code, but it didn't worked

$asset1 = Pimcore\Model\Asset::getById(132);       // 132 -> asset id 
$asset1->setParentId(11); //11 is the id of the folder created in pimcore. Want to move asset to this folder.
$asset1->save();

Upvotes: 0

Views: 1675

Answers (1)

sir_neromani
sir_neromani

Reputation: 83

Try using:

$parent = Pimcore\Model\Asset::getById(11);
$asset->setParent($parent);
$asset->save();

Upvotes: 1

Related Questions