PHPSpert Posted July 26, 2014 Share Posted July 26, 2014 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(); Link to comment Share on other sites More sharing options...
adrian Posted July 26, 2014 Share Posted July 26, 2014 What about this: $np = $pages->clone($page); $np->of(false); $np->title = 'New Page'; $np->name = 'newpage'; $np->save(); 11 Link to comment Share on other sites More sharing options...
PHPSpert Posted July 27, 2014 Author Share Posted July 27, 2014 Thanks, that worked for me Link to comment Share on other sites More sharing options...
Macrura Posted October 26, 2014 Share Posted October 26, 2014 @adrian - thanks for the api clone.. just saved me a lot of searching! Link to comment Share on other sites More sharing options...
dragan Posted July 1, 2018 Share Posted July 1, 2018 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. 1 Link to comment Share on other sites More sharing options...
adrian Posted July 1, 2018 Share Posted July 1, 2018 @dragan - I just tested your code here without any problems: 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. 2 Link to comment Share on other sites More sharing options...
dragan Posted July 1, 2018 Share Posted July 1, 2018 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now