ContentType + Page model add function + cParentID

Permalink
ContentType is supposedly synonymous with PageType "The CollectionType or PageType object represents reusable types of pages that can be added to a Concrete site". What object uses cParentID? I am trying to use models to add Page dynamically in code but I receive this error ".. EXECUTE("select max(cDisplayOrder) from Pages where cParentID = LIMIT 1") " I've set the ContentType to a desired PageType object and passed to the Page add() function as $ct. Do I need to set the parent of the new Page and if so, how? I can't seem to set the desired value for cParentID and there is no relative $data array element. According to the query string error message it needs a value for cParentID. I'll keep trying and if I figure it out I'll update my post.

Follow up ...

I set $page->cID to desired cParentID and I get farther, but now get error "1048: Column 'cOverrideTemplatePermissions' cannot be null". I set that to 1 but then I keep getting more errors for missing values so it seems like I need to initialize the Page object, not just pass the parameters to the add function.

Anyone have insight or done this before? Thanks!

 
ryan replied on at Permalink Reply
ryan
Take a look at the install of sample content in concrete's install controller:
/concrete/controllers/install.php

That has examples of code that adds pages, page types & blocks.

This code adds a page below the current page. I'm not 100% on the collection type line, but it's close to that.
$c = Page::getCurrentPage();
$ct = CollectionType::getByHandle('default');
$data = array();
$data['uID'] = 1;
$data['name'] = 'Your page name';
$newpage = $c->add($ct, $data);
myregistration replied on at Permalink Reply
Thanks for pointing me in the right direction. The problem was the Page object wasn't initialized. I am creating a new Page from a script so I need to init Page using the parent id of the new page and then call the add function. I've included example code below in case anyone else needs it. Thanks for your help!

Loader::model('collection_types');
Loader::model('page'); 
$dt = Loader::helper('form/date_time');
$ct = CollectionType::getByHandle('member'); // or can use getByID(#)
// $data may contain any or all of the following elements; See add() function in /concrete/models/page.php
$data = array(
   "uID" => 1,
   "pkgID" => 0,
   "cName" => "New Page Title",
   "cHandle" => "new_page_handle",
   "cDatePublic" => $dt->translate('cDatePublic')
);
// init new page's parent, argument is cID of the parent
$page = Page::getByID(1); 
$newpage = $page->add($ct, $data);