Jump to content

Recommended Posts

Posted

I'm trying to clone a page, it's repeater fields and other values to another page.

will something like this work?

$newPage = clone $page;
$newPage->id = null;
$newPage->name = "new-slug";
$newPage->save();
Posted

What about this:

$np = $pages->clone($page);
$np->of(false);
$np->title = 'New Page';
$np->name = 'newpage';
$np->save();
  • Like 11
  • 2 months later...
  • 3 years later...
Posted

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
Posted

@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
Posted

Yeah, I was just to post a follow-up. I ran the same code in another PW installation and it worked without any problems. I guess it's some module that gets in the way.

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
  • Recently Browsing   0 members

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