Jump to content

Simple page select produces odd errors


Peter Knight
 Share

Recommended Posts

I have a homepage with a Page field which allows client to choose a single page.

<?php
  foreach ($page->feat_home_pptv as $pptv) {
  echo"test"
  ;}
?>

This echoes 22 "test" on the page even though the Page field is limited to a single Page

Ok, I thought. Lets try this with some real content ...

<?php
  foreach ($page->feat_home_pptv as $pptv) {
  echo"{$pptv->title}"
  ;}
?>

The above produces produces an odd looking error referencing a CommentArray

Error: Exception: Class 'CommentArray' doesn't yet implement method 'makeBlankItem()' and it needs to. (in /var/www/vhosts/domain.com/httpdocs/wire/core/WireArray.php line 131)

#0 /var/www/vhosts/domain.com/httpdocs/wire/core/WireArray.php(1457): WireArray->makeBlankItem()
#1 /var/www/vhosts/domain.com/httpdocs/wire/core/WireArray.php(443): WireArray->usesNumericKeys()
#2 /var/www/vhosts/domain.com/httpdocs/wire/core/WireArray.php(464): WireArray->get('title')
#3 /var/www/vhosts/domain.com/httpdocs/site/templates/home.php(88): WireArray->__get('title')
#4 /var/www/vhosts/domain.com/httpdocs/wire/core/TemplateFile.php(182): require('/var/www/vhosts...')
#5 [internal function]: TemplateFile->___render()
#6 /var/www/vhosts/domain.com/httpdocs/wire/core/Wire.php(397): call_user_func_array(Array, Array)
#7 /var/www/vhosts/domain.com/httpdocs/wire/core/Wire.php(332): Wire->runHooks('render', Array)
#8 /var/www/vhosts/domain.com/httpdocs/wire

This error message was shown because you are logged in as a Superuser. Error has been logged.

The selected page's template doesn't have any comments markup html but it did have a comment field assigned to the template.

I removed the comments field from the template and the selector produces no content

<?php
foreach ($page->feat_home_pptv as $pptv) {
echo"{$pptv->title}"
;}
?>

I'm running ProcessWire 2.6.14, MYSQL 5.5.41


Adding find('limit=1') works and produces no errors

<?php
foreach ($page->feat_home_pptv->find('limit=1') as $pptv) {
echo"{$pptv->title}";}
?>

I'm not sure why it needs that find('limit=1') as the field itself is set to only allow a single page

Link to comment
Share on other sites

If it's a single page select then you don't foreach as it's not an PageArray. It's the page object already.

if($page->feat_home_ppty) {
    echo $page->feat_home_ppty->title;
}

Not sure why that comments playing a role here when doing it wrong.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...