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
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 } ?>
I placed on the line above 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.
echo $c->getAttribute('tour_code');
foreach($holiday_types as $holiday_type) { ?>
Makes sense as the block works fine in child pages, just don't seem to be able to edit via Edit Default.
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.
I'm not sure if this is the problem.
The problem only arises when the block includes
I don't have the problem with other blocks that use and call the same page attribute.
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.
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.
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.
Outside of that other function call, does it return what you are expecting?