Jump to content

Save Page Type field with multiple pages programatically


SwimToWin
 Share

Recommended Posts

How can I programatically Save() to a Page Type field that contain multiple pages (PageArray)?

This attempt fails with no error message, nothing is saved:

$p = $pages->get(1234);
$p->of(false);
$p->foo = 4321; # Page Type field, I am trying to update the ID.
// $p->foo = "bar";
// $p->foo->id = 4321; # Results in "Fatal error:  Exception: Item 'id' set to PageArray is not an allowed type".
$p->save();

Observation: It's hard to search documentation and forum entries for this topic because the keywords Page, Type and Save are frequently used in different contexts. I guess the most logical place to find information would be on 1) the "API Variable > $page" page - and/or, the "API Variable > FieldTypes" page. My request is that the documentation at some point will cover how to programatically CRUD each core field type (Checkbox, Datetime, Email, FieldsetOpen, FieldsetTabOpen, File, Float, Image, Integer, Page, Password, (Repeater), Text, Textarea, URL).

Merry Christmas and thanks.

Related:

Link to comment
Share on other sites

This will do what you are looking for. You need to get the page array for the page you are adding: $pageitem and also use "add" to add it to the array of pages held by the page field.

$p = $pages->get(1234);
$pageitem = $pages->get(4321);
$p->of(false);
$p->foo->add($pageitem);
$p->save();

Hope that makes sense.

  • Like 5
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

×
×
  • Create New...