Can we create/update a page using PHP?
Permalink
Hello there, wonder if anyone can help.
I am trying to write a script that will used on a daily basis to check to see if a certain page exists.
We will be updating it if so, creating it if not.
Currently I can check to see if the page exists:
//Build the page path
$pagepath = "/listings/" . $category . "/" . $propertyid;
//Try to find a page at that path
$page = Page::getByPath($pagepath, 'RECENT');
//Check to see if we have a page.
$cID = $page->cID;
if (!$cID){
//Page does not exist - Create
}else{
//Page Exists - Update
}
(Please correct me if there's a better way of doing this)
Would anyone know if it's possible for me to create a page purely in PHP?
Would I need to deal with the database tables direct or is there a Concrete5 function/set of functions?
Any advice appreciated.
I am trying to write a script that will used on a daily basis to check to see if a certain page exists.
We will be updating it if so, creating it if not.
Currently I can check to see if the page exists:
//Build the page path
$pagepath = "/listings/" . $category . "/" . $propertyid;
//Try to find a page at that path
$page = Page::getByPath($pagepath, 'RECENT');
//Check to see if we have a page.
$cID = $page->cID;
if (!$cID){
//Page does not exist - Create
}else{
//Page Exists - Update
}
(Please correct me if there's a better way of doing this)
Would anyone know if it's possible for me to create a page purely in PHP?
Would I need to deal with the database tables direct or is there a Concrete5 function/set of functions?
Any advice appreciated.
Hi There.
That's where I was hoping to place my functionality in the end, yes.
However, I can't find out if there's a Concrete5 function to create/update a page programmatically, so to speak.
Looks like I might have to interact with the database directly.
That's where I was hoping to place my functionality in the end, yes.
However, I can't find out if there's a Concrete5 function to create/update a page programmatically, so to speak.
Looks like I might have to interact with the database directly.
Check the Page documentation here :
http://www.concrete5.org/documentation/developers/pages/overview...
You can simply use the Page::add() function
and $page->update($data) for update a page.
http://www.concrete5.org/documentation/developers/pages/overview...
You can simply use the Page::add() function
$page = Page::add(CollectionType $pageType, $data) Adds a new page of type $pageType, setting the various provided fields in the $data array. This array may contain: "uID": User ID of the page's owner "pkgID": Package ID the page belongs to "cName": The name of the page "cHandle": The handle of the page as used in the path "cDatePublic": The date assigned to the page
and $page->update($data) for update a page.
Hope this help!