getPageContent and $allowCreate

Hi,

I have a situation where I link an album (artist) to their page (bio). So the common identifiers are $_zp_current_album->getFolder() and the page titlelink. So on the artist album and image pages, I can call the bio information from a page with:
`

<?php if (getPageContent($_zp_current_album->getFolder())) {
printPageContent($_zp_current_album->getFolder());
} else { ?>

Their is no Bio page set up for this artist yet, please contact us to set one up.

<?php } ?>

`
This may not be the best way to do it, I am not sure, but my issue is when the client creates a new album (artist), without also creating the corresponding bio page, if the album is browsed, an empty page with the title link is created. I would have thought the getPageContent() would have returned false.

Tried to follow the linkage of this function:
`
function ZenpagePage($titlelink, $allowCreate=NULL) {
$new = parent::PersistentObject('pages', array('titlelink'=>$titlelink), NULL, true, empty($titlelink), $allowCreate);
}
`
to the persistent object, etc and came across the $allowCreate variable but cannot seem to set this to false so that an empty page is not created.

Hope this makes sense, any suggestions much appreciated, especially if you have an idea for a better way to accomplish this.

Cheers!

Comments

  • acrylian Administrator, Developer
    So calling the page content of an non existing page creates that page? That should not happen unless you set $allowCreate to true and do a $page->save() on the object and would probably be a bug... I will try to reproduce that.

    You could workaround this by using the `getPages()` Zenpage class method and do a simple loop to check if the page actually exists.
    `
    $pages = $_zp_zenpage->getPages(); // for backward compatibility this currently still returns all fields not just the titlelink
    foreach($pages as $page) {
    if($_zp_current_album->name == $page['titlelink']) {
    ...
    }
    }
    `
  • gjr Member
    Thanks acrylian - your alternative works perfectly!
    So calling the page content of an non existing page creates that page?
    Yes that is correct. When looking at the page tab and database, a new untitled page is created with all fields null except the titlelink and ID.

    Again, thanks for your help -
  • Well, actually, passing NULL to a parameter normally will select its default setting. In the case of persistentObject, this default is to allow the creation. So if you want to create the page only if it does not exist, pass `false` as the allowCreate parameter in `new ZenpagePage()`

    In your case you will have to explicitlycheck for existence as the `printPageContent()` presumes the page exists.
Sign In or Register to comment.