Call to a member function xpath() on a non-object

Permalink
Hello,

When I load a certain block into a page type and then try to view the page type via Edit Defaults I get "Call to a member function xpath() on a non-object". However, I can still see the output of the block on the child pages fine.

I think the problem is something to do with using page attributes, because when I take out '$c->getAttribute('tour_code')' and replace it with with a static number (e.g. 23) everything is fine and I am able to view the page type via Edit Defaults.

Any ideas?

View.php
<?php  defined('C5_EXECUTE') or die("Access Denied.");
         include('config.php');
         $tc = new TourMKT($marketplace_account_id, $api_private_key, "simplexml");
         $c = Page::getCurrentPage();
         $result = $tc->show_tour($c->getAttribute('tour_code'), $channel_id);
         $tour = $result->tour;
         $holiday_types = $tour->xpath('categories/group[name="Holiday type"]/values/value');
               foreach($holiday_types as $holiday_type) { ?>
               <div class="holiday-type-tt" style="background-color:#F7F7F7; text-align:center;">Holiday type: <strong><?php echo $holiday_type.'';?></strong></div>
                   <?php
                    }
?>

 
hutman replied on at Permalink Reply
hutman
If you do an echo of

$c->getAttribute('tour_code');


Outside of that other function call, does it return what you are expecting?
PJSAndo replied on at Permalink Reply
I placed
echo $c->getAttribute('tour_code');
on the line above
foreach($holiday_types as $holiday_type) { ?>
and it worked fine, displayng teh tour code on the child page.

Makes sense as the block works fine in child pages, just don't seem to be able to edit via Edit Default.
hutman replied on at Permalink Best Answer Reply
hutman
Unfortunately this won't work as you are hoping on the Edit Defaults, because the default page doesn't have this attribute. What you could do is set that to a variable and then if it doesn't exist default it to a number.
PJSAndo replied on at Permalink Reply
I'm not sure if this is the problem.

The problem only arises when the block includes
$tour->xpath('custom_fields/field[name="shortitin"]/value');?>


I don't have the problem with other blocks that use and call the same page attribute.
PJSAndo replied on at Permalink Reply
Hi hutman,

You were right. I entered a default value into the attribute within the page type and I can now edit via Edit Default.

Thanks for that.