joer80 Posted March 9, 2016 Share Posted March 9, 2016 I am not sure if I am using the api wrong or if something is broken. Been stuck for a bit. The page I am on has a page field I am using for a select option. I am not able to read it with api. I need to print out its title but it is coming back as empty or null even though it is set. $page->BaseStyle->title;Take a look at the attached screenshot! Thanks in advance for any help you can give! Link to comment Share on other sites More sharing options...
horst Posted March 9, 2016 Share Posted March 9, 2016 Fieldname BaseStyle has Uppercase letters. Try to rename / use only lowercase letters. Check the fieldname in DB, (field_BaseStyle or field_basestyle) Link to comment Share on other sites More sharing options...
joer80 Posted March 9, 2016 Author Share Posted March 9, 2016 Case doesnt seem to matter. If I do this: echo "<pre>"; var_dump($page->basestyle); //(now all lowercase) echo "</pre>"; foreach($page as $field => $value) { echo "$field = $value <br />"; } It shows this: NULL id = 1016 Design_Settings = BaseStyle = MiddleStyle = Design_Settings_END = $page->basestyle->title is also empty. Link to comment Share on other sites More sharing options...
BitPoet Posted March 9, 2016 Share Posted March 9, 2016 Can you make sure it isn't a permissions issue (e.g. /styles/base/black being hidden)? 2 Link to comment Share on other sites More sharing options...
joer80 Posted March 9, 2016 Author Share Posted March 9, 2016 You the man! As soon as I checked "Make field value accessible from API even if not viewable (see below)*" it showed up! All I checked was manage access control. What role does the api run as? Link to comment Share on other sites More sharing options...
BitPoet Posted March 9, 2016 Share Posted March 9, 2016 The api runs as the logged-in user, or as guest if you're not logged in. Link to comment Share on other sites More sharing options...
joer80 Posted March 9, 2016 Author Share Posted March 9, 2016 Ah.. My first instinct for an important field is to remove guest access. Should this api checkbox be enabled by default? Or is it common that you would want to block the api from reading roles manged fields by default? Link to comment Share on other sites More sharing options...
BitPoet Posted March 9, 2016 Share Posted March 9, 2016 I don't think checking it by default would be sensible. Usually, access is managed by template permissions and hidden/published status on the selectable pages. Any widening of access rights should have to be done explicitly. Link to comment Share on other sites More sharing options...
joer80 Posted March 9, 2016 Author Share Posted March 9, 2016 What about adding an api role so its different from users not logged in? 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