Jump to content


Photo

Strange missing field in $page array


  • Please log in to reply
15 replies to this topic

#1 DaveP

DaveP

    Sr. Member

  • Members
  • PipPipPipPip
  • 285 posts
  • 135

  • LocationChorley, UK

Posted 16 March 2012 - 07:27 AM

I have a template with several fields, all of which work perfectly as expected, except for one field which is broken in some way. The field itself shows up in the $page array, but is empty, even though another template and the PW admin both correctly show the field's contents. Dumping $page->fields doesn't even show the field at all.

Any ideas?

<edit>I have other PW sites working on the same web server without any problems.</edit>

Edited by DaveP, 16 March 2012 - 08:19 AM.

Twitter : Facebook : GitHub : G+ : Blog : Powered by C8H10N4O2 and C10H14N2

#2 diogo

diogo

    Hero Member

  • Moderators
  • 1,990 posts
  • 1067

  • LocationPorto, Portugal

Posted 16 March 2012 - 09:12 AM

what kind of field? does it work on other templates?

#3 DaveP

DaveP

    Sr. Member

  • Members
  • PipPipPipPip
  • 285 posts
  • 135

  • LocationChorley, UK

Posted 16 March 2012 - 09:31 AM

what kind of field? does it work on other templates?


It's a text field - I changed it to a textarea and back again and neither worked.

another template and the PW admin both correctly show the field's contents


:)
Twitter : Facebook : GitHub : G+ : Blog : Powered by C8H10N4O2 and C10H14N2

#4 diogo

diogo

    Hero Member

  • Moderators
  • 1,990 posts
  • 1067

  • LocationPorto, Portugal

Posted 16 March 2012 - 09:48 AM

Sorry Dave :)

#5 DaveP

DaveP

    Sr. Member

  • Members
  • PipPipPipPip
  • 285 posts
  • 135

  • LocationChorley, UK

Posted 16 March 2012 - 09:56 AM

No problem :P
Twitter : Facebook : GitHub : G+ : Blog : Powered by C8H10N4O2 and C10H14N2

#6 ryan

ryan

    Hero Member

  • Administrators
  • 5,771 posts
  • 3112

  • LocationAtlanta, GA

Posted 16 March 2012 - 10:00 AM

DaveP, can you try this from your template:

var_dump($page->field);

Replacing 'field' with the name of that field. See what it tells you.

Since this is a textarea field, check what Text formatters are applied to it on the 'details' tab of your field settings. Try removing any temporarily and testing again (just don't forget to add them back). Let us know what you find.

#7 DaveP

DaveP

    Sr. Member

  • Members
  • PipPipPipPip
  • 285 posts
  • 135

  • LocationChorley, UK

Posted 16 March 2012 - 10:20 AM

It's NULL, which is really weird. The $page object contains all the other fields on that template - they are all echoed successfully. That field is only used on 1 template, but is referenced successfully by other pages as a child page field, and shows in the PW admin no problem.

Edit Field phone - Google Chrome 16032012 151122.jpg

Edit Page • ProcessWire - Google Chrome 16032012 151054.jpg

<edit>Found a cure - set autojoin, which made the field show up where it was expected. But it shouldn't need autojoin on to be available with the page, should it?</edit>
Twitter : Facebook : GitHub : G+ : Blog : Powered by C8H10N4O2 and C10H14N2

#8 ryan

ryan

    Hero Member

  • Administrators
  • 5,771 posts
  • 3112

  • LocationAtlanta, GA

Posted 17 March 2012 - 07:51 AM

Glad you found a cure, but it's still a mystery. Definitely shouldn't need autojoin to work. I am wondering if you rename the field if that changes anything, like renaming it to 'telephone' rather than 'phone'. That would at least tell us if there were any issues in the table name, or if 'phone' is a reserved word somewhere (though it's not in PW). I'm also still curious what you have set for 'Text formatters' in your field 'details' tab? The text formatters only apply to the front-end, where you were getting NULL, so I'm curious if a text formatter was failing and causing the NULL. I did try to duplicate here creating a text field called 'phone' but everything worked normally. It would be great if we could find a way to duplicate it because this is a strange one.

Thanks,
Ryan

#9 DaveP

DaveP

    Sr. Member

  • Members
  • PipPipPipPip
  • 285 posts
  • 135

  • LocationChorley, UK

Posted 17 March 2012 - 08:33 AM

Ryan, I tried renaming the field, to no avail, and I made a new one, named slightly differently, which didn't show up either. There are no text formatters active on the field.

Here's the field in phpMyAdmin
screenshot.png

There are quite a few other things I will try when I get time - for example, if I need to add another (unrelated) field, I don't know if that will work as expected, although the autojoin fix gives me confidence. I will also overwrite my 'wire' folder with a fresh download just in case something got corrupted somehow.

I had a good look around the tables in the db and couldn't see anything that looked wrong on the face of it. The site has been migrated from my development machine, so I initially wondered if that was an issue, but when I looked back at the development system, the field was misbehaving there as well - I just hadn't noticed!

It isn't a reserved word, as you point out, in PW (I had found the list in the PW source), and my application is just hand coded web pages, so there's no kind of conflict with another system.

Cheers.
Twitter : Facebook : GitHub : G+ : Blog : Powered by C8H10N4O2 and C10H14N2

#10 Soma

Soma

    Hero Member

  • Moderators
  • 3,186 posts
  • 1743

  • LocationSH, Switzerland

Posted 17 March 2012 - 08:48 AM

Have you tried doing a table/db repair?

@somartist | modules created | support me, flattr my work flattr.com


#11 ryan

ryan

    Hero Member

  • Administrators
  • 5,771 posts
  • 3112

  • LocationAtlanta, GA

Posted 17 March 2012 - 08:49 AM

Thanks for your testing here. It's generally a good idea to have some kind of text formatter on your text fields, because otherwise they are unfiltered (could contain HTML, etc.). So I usually add an entities text formatter to fields like a phone number. I would be curious to know if actually adding a text formatter to it (like entities) produces any change.

In your code where you are examining the value with var_dump(), is there anything that occurs before it? Or is this at the very top of your template file?

Do you have any modules installed in your /site/modules/ dir?

Thanks,
Ryan

#12 DaveP

DaveP

    Sr. Member

  • Members
  • PipPipPipPip
  • 285 posts
  • 135

  • LocationChorley, UK

Posted 17 March 2012 - 11:44 AM

Ryan, I may have said this before, but you are a genius.

In your code where you are examining the value with var_dump(), is there anything that occurs before it? Or is this at the very top of your template file?


The offending code is this, which appears in the <head> of the document.
<title><?php
echo $page->get("headline|title");
if($page->template = 'mytemplate') echo ', '.$page->parent->title;
?> | mysitename</title>
The page hierarchy at this point in skyscraper terms is /new-york-city/chrysler-building/ so what I'm trying to do is build a nice SEO friendly page title of 'Chrysler Building, New York City | mysitename'.

If I var_dump($page->phone) before the 'if' statement, it is fine. After, it ain't there. The really strange thing is that all the other page fields are!

Anyhow, am I doing something wrong? Is there a better way of phrasing the 'if' statement? Why does autojoin cure the problem?

Answer as few or as many of these questions as you prefer. :mellow:
Twitter : Facebook : GitHub : G+ : Blog : Powered by C8H10N4O2 and C10H14N2

#13 Pete

Pete

    Administrator

  • Administrators
  • 1,756 posts
  • 657

  • LocationChester, England

Posted 17 March 2012 - 01:01 PM

If($page->template =

Should be:

If($page->template ==

#14 DaveP

DaveP

    Sr. Member

  • Members
  • PipPipPipPip
  • 285 posts
  • 135

  • LocationChorley, UK

Posted 17 March 2012 - 01:09 PM

Thanks, Pete. Aaargh! My bad. How embarrassing. Makes me wish I never learnt BASIC. :-[
(Of course that fixes it.)
Twitter : Facebook : GitHub : G+ : Blog : Powered by C8H10N4O2 and C10H14N2

#15 Pete

Pete

    Administrator

  • Administrators
  • 1,756 posts
  • 657

  • LocationChester, England

Posted 17 March 2012 - 02:29 PM

Hehe, no problem - I still do that from time to time and I have no excuse since PHP is my first programming language ;)

#16 ryan

ryan

    Hero Member

  • Administrators
  • 5,771 posts
  • 3112

  • LocationAtlanta, GA

Posted 18 March 2012 - 08:25 AM

I think that the '=' vs '==' is a common thing everyone runs into in any language that uses that assignment vs. comparison style. (PHP, Javascript, Java, C/C++, etc.). Running into this on occasion just goes with the territory, regardless of how long you've been doing it. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users