Jump to content
gunter

[solved] adding virtual (non saved) pages to pageArray?

Recommended Posts

$calendarPageArray = pages->find($selector);
$p = new Page(); // create new page object
//some page stuff...
$calendarPageArray->add($p);

I found out that it doesn´t seem to be possible to add an unsaved page to the pagearray...
It´s  for a worktime scheduling calendar... a have some real pages with the weekdays and their worktime... and I have also pages with special calendar days with special worktime.. I want get the calendar days from the pagetree into a pagearray... and then adding the generic weekdays as somehow virtual unsaved pages into that pagearray...

 

 

Share this post


Link to post
Share on other sites

You need to give it a template, name, title:

image.png.88c6bfc8a89a74da2672702ef9a4495a.png

  • Like 2

Share this post


Link to post
Share on other sites

Aaahhhh!! A name! That's it, I didn'nt gave one! Thanks so much, Adrian!!!

  • Like 1

Share this post


Link to post
Share on other sites

 Adrian,please... how did you get that clean pagearray debugging info into the bottom screen? 🙂

image.png.54bd12ee5846b7ae6f801cda73942376.png

 

 

 

 

Share this post


Link to post
Share on other sites

Yep d() for dumping to the current output (either the console results or the template file where you call it from), or bd() for bardump which dumps to a dedicated Dumps panel on the Tracy debug bar.

Share this post


Link to post
Share on other sites
    $days = 20;    
    $selector = "template=basic-page";
    $resultPageArray = $this->pages->find($selector);
for($i=0;$i<=$days;$i++){
    $p= new Page();
    $p->template = 'basic-page'; // set template
    $p->title = rand();
    $p->name = "virtual-page".rand();
    $resultPageArray->add( $p);
}
d($resultPageArray);

the dumping function is very useful!
Unfortunately I have a problem, this code should in my opionion add 20 pages to items... but only one page gets added, the rest are under $resultPageArray->itemsAdded

image.png.925e8b2833cbe7d1b5da31978300d704.png

 

 

Share this post


Link to post
Share on other sites


problem solved! I have to set a unique id -> then the code from my last posting works - without setting the id -> just one page (the last one) is getting added to the page array

    $p->id = rand();

 

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...