DaveP Posted March 16, 2012 Share Posted March 16, 2012 (edited) 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 March 16, 2012 by DaveP Link to comment Share on other sites More sharing options...
diogo Posted March 16, 2012 Share Posted March 16, 2012 what kind of field? does it work on other templates? Link to comment Share on other sites More sharing options...
DaveP Posted March 16, 2012 Author Share Posted March 16, 2012 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 Link to comment Share on other sites More sharing options...
diogo Posted March 16, 2012 Share Posted March 16, 2012 Sorry Dave Link to comment Share on other sites More sharing options...
DaveP Posted March 16, 2012 Author Share Posted March 16, 2012 No problem Link to comment Share on other sites More sharing options...
ryan Posted March 16, 2012 Share Posted March 16, 2012 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. Link to comment Share on other sites More sharing options...
DaveP Posted March 16, 2012 Author Share Posted March 16, 2012 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>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> Link to comment Share on other sites More sharing options...
ryan Posted March 17, 2012 Share Posted March 17, 2012 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 Link to comment Share on other sites More sharing options...
DaveP Posted March 17, 2012 Author Share Posted March 17, 2012 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 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. Link to comment Share on other sites More sharing options...
Soma Posted March 17, 2012 Share Posted March 17, 2012 Have you tried doing a table/db repair? Link to comment Share on other sites More sharing options...
ryan Posted March 17, 2012 Share Posted March 17, 2012 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 1 Link to comment Share on other sites More sharing options...
DaveP Posted March 17, 2012 Author Share Posted March 17, 2012 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. Link to comment Share on other sites More sharing options...
Pete Posted March 17, 2012 Share Posted March 17, 2012 If($page->template = Should be: If($page->template == 2 Link to comment Share on other sites More sharing options...
DaveP Posted March 17, 2012 Author Share Posted March 17, 2012 Thanks, Pete. Aaargh! My bad. How embarrassing. Makes me wish I never learnt BASIC. (Of course that fixes it.) Link to comment Share on other sites More sharing options...
Pete Posted March 17, 2012 Share Posted March 17, 2012 Hehe, no problem - I still do that from time to time and I have no excuse since PHP is my first programming language Link to comment Share on other sites More sharing options...
ryan Posted March 18, 2012 Share Posted March 18, 2012 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now