Jump to content

Easy Way To Clone A Page From Api?


PHPSpert
 Share

Recommended Posts

  • 2 months later...
  • 3 years later...

What's the correct way to clone an entire page with child pages? I tried the following and always get the same error:

$from = $pages->get(1421);
$to = $pages->get(1411);
$from->of(false);
$to->of(false);
$newPage = $pages->clone($from, $to);
$newPage->of(false);
$newPage->name = $from->name;
$newPage->title = $from->title;
$newPage->save();

the error:

Exception: Can’t save page 0: /kurse-weiterbildung/kurse-trainings/maschinen-methoden-konzepte/maschinenkonzepte/: Call $page->of(false); before getting/setting values that will be modified and saved. [Page::statusCorrupted] fields: images on line: 508 in /wire/core/PagesEditor.php

My intention is to clone the branch (page with children), move it to another place, and keep titles and page-names intact. I understand you can't have the same page-names at the same page-level, therefore PW adds an increment. When I run the above code, only the parent page is created, with page-name-1.

  • Like 1
Link to comment
Share on other sites

@dragan - I just tested your code here without any problems:

cloning.thumb.gif.b17ffdc287427e2206723351d8cd056c.gif

 

But based on the error message, it looks like the images field is corrupted somehow. I have never come across this before, but that is where to start looking.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...