Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Inconsistent Call to a member function getField() on a non-object error


This topic is 5611 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I have a fairly large php website that has company records that can appear on the same page but get there via different categories. Here's my problem...

I can do:

Record A to Page 1a to Page 2 = no problems

Record B to Page 1a to Page 2 = no problems

but...

Record B to Page 1b to Page 2 = ERROR

The issue is that the links being passed appear exactly the same and the error only occurs when I place fields in the

and tags. I can comment out those tags and I don't get the error even though the same fields appear later on the page.

Here is a link cut-and-pasted from Page 1a:

$link = $siteURL.$record->getField('web__Contact_by_cCategoryActiveSponsor::cContactIDandCompany');




Here is a link cut-and-pasted from Page 1b:


$link = $siteURL.$record->getField('web__Contact_by_cCategoryActiveSponsor::cContactIDandCompany');




Here is an actual link:


http://www.woodencrates.org/nefab-C202063




Here is the .htaccess rewrite:


RewriteRule ^([^/]*)-(C[0-9]{6}) sponsor.php?id=$2 [NC,L]




Here is the find:


$findreq->addFindCriterion('ContactID', "=="".$_GET['id']).""";

I'm pretty dumbfounded by this. Has anyone experienced this before or have any suggestions for how I can test it?

Thanks much

Posted

As luck would have it, after spending many hours trying to figure this out then posting the question, I got it fixed.

I'm not sure why it's happening but what is happening is I have a calculation to identify the content of the php page being displayed (an internal page name for relationships) then an include grabs all the metadata and populates the metadata tags as appropriate for that particular web page content.

On these web pages, the metadata comes from the table that includes the actual content to be displayed, not from the metadata table as is usually the case. If the metadata table record doesn't exists, the error occurs. That's the case here. In my example above where the same record would display once and error out in the other case, the only difference was the missing record from the metadata table that identifies the category that the record as it is being displayed is being associated with.

It seems like a bug(?)

Posted

The site has a pretty long .htaccess file and a variety of includes.

I can post much more if anybody wants to see it but I didn't want to post a bunch of confusion.

Let me know if you want to see more.

Posted

The htaccess is likely irrelevant here as while it may be providing a potentially invalid find criterion, your issue relates to the fact that you're trying to call the getField() method on an object that is not a valid record object - most likely you've failed to trap for an error immediately following your find somewhere.

Hence why I say you have not posted enough code - you are not showing how you have obtained the record object (supposedly stored in the $record variable) which is what the relevant point is here.

Posted (edited)

In fact, re-reading your statement:

If the metadata table record doesn't exists, the error occurs. That's the case here. In my example above where the same record would display once and error out in the other case, the only difference was the missing record from the metadata table that identifies the category that the record as it is being displayed is being associated with.

You state that the record is missing, and yet that you are trying to call getField() on the $record variable? Presuming that you used the following to obtain your "record":

$result = $find->execute();

$result would be an error object, instead of a result set object. The question is though, how the heck do you manage to do a call on $result to get your "$record" variable in the first place - that should also have thrown an error.

Bet's are on that you have done the following:


<?php

If( !FileMaker::isError($result) ) {

$record = $result->getFirstRecord();

}

?>

<?php echo $record->getField("title"); ?>





Now, in the above, if an error is thrown (a record not found error - 401 is an error) then the $record variable is not set. Further in the code you do not do a necessary check to see if the $record variable was ever set and try to do a call on what PHP would consider to be a string...

This is expected behavior and by no means any form of bug.



A valid work around would be:



<?php

If( !FileMaker::isError($result) ) {

$record = $result->getFirstRecord();

}

?>

<?php if( isset($record) ) echo $record->getField("title"); ?>

Edited by Guest
Had error checks inversed
Posted

My foreach loop to get the FM records is typically at the beginning of the parent page. In this case it was in an include() after trying to populate the metadata. The code itself was correct but in the wrong order.

I typically cut-and-paste the FM code from/to the top of every page but most all my pages have a shell/parent page and a body/child page (I don't know if there's a real term for this). In this case, I was getting the records in the child page, after I was trying to use them.

At this point, I don't know what was causing the confusing results that I originally posted, but I don't care to dig into it. I'm just happy it's working.

In retrospect, I would say you're absolutely right about the .htaccess file being irrelevant. Using it just throws my head into a tizzy. I'm using it to create friendly URLS but I've never touched RegEx until I started with it. I reuse many php pages for many different web pages. To make my FM tables friendlier, (I though) it was easier to make the .htaccess file do more work. This has proven to make things very uncomfortable for me.

Although I already figured it out, your posts made it clear that I have to increase my comfort level with PHP and the FM API. I've gotten by so far without studying either but I think it's time to start so issues like this won't seem so confusing.

Thanks much

Thanks much

Posted

Hey sorry,

Wasn't trying to be "in your face" about it - just trying to make a point that it's hard to debug something like this if the relevant code hasn't been posted.

Posted

? No offense taken and I DO appreciate the assistance.

Your questions made me stop and think, and I did learn something from them. I skipped over the RTFM process and shouldn't have.

In other forums, I've found that when I post a lot of lines of code, I rarely get a response so I try to be brief.

This topic is 5611 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.