fbg13 Posted May 21, 2017 Share Posted May 21, 2017 49 minutes ago, Thor said: But for the hell of me, I have tried every possible combination for 1 hour now, and I cannot find how to do the reserve. Save data !!! Why is it so hard to find this information? I gave you an example in my second reply. Link to comment Share on other sites More sharing options...
Thor Posted May 22, 2017 Author Share Posted May 22, 2017 17 hours ago, diogo said: Are you getting any error message? Can you try this and see if it works? $user->of(false); // this disables output formatting $user->my_planet = "mars"; $user->save('my_planet'); Does nothing. No errors. I also check the table in the MySQL database and nothing is saved. Link to comment Share on other sites More sharing options...
Thor Posted May 22, 2017 Author Share Posted May 22, 2017 16 hours ago, fbg13 said: I gave you an example in my second reply. Do you mean this? $u->of(false); // http://cheatsheet.processwire.com/page/built-in-methods-reference/page-setoutputformatting-true-false/ $u->name = "whatever"; $u->save(); It gives me a 500 errors. I can pull data out of my field. But I cannot save anything to it. Link to comment Share on other sites More sharing options...
fbg13 Posted May 22, 2017 Share Posted May 22, 2017 @Thor that's because $u is empty , unless you assign an user object to it. $u = $pages->get("template=user, name=username"); // or $u = $users->get("username"); And with your other example above. Are you logged in while running that code? Did you add the my_planet field to the user template? Link to comment Share on other sites More sharing options...
Thor Posted May 22, 2017 Author Share Posted May 22, 2017 Ok, tried this instead: $u = $users->get("username"); $u->of(false); // http://cheatsheet.processwire.com/page/built-in-methods-reference/page-setoutputformatting-true-false/ $u->my_planet = "mars"; $u->save(); Same error 500 with your code. No difference. Logs in the admin side say: (line 387 of /home/example/public_html/wire/core/PagesEditor.php) Yes, the field is added to the template. And yes, I'm loading the page logged as the user from another browser. Link to comment Share on other sites More sharing options...
fbg13 Posted May 22, 2017 Share Posted May 22, 2017 54 minutes ago, Thor said: Does nothing. No errors. I also check the table in the MySQL database and nothing is saved. Are you sure you are logged in? If you're not logged in it saves to the guest user. $u = $users->get("username"); username should be the name of the user you want to edit/save. If this are not the problem I don't know. If you test this on a server I could take a look, if you're ok with giving me access. 1 Link to comment Share on other sites More sharing options...
Thor Posted May 22, 2017 Author Share Posted May 22, 2017 If put the username no 500 error anymore. But of course, just like with all my other tests, no data is saved to the field. So I tried another field before giving up, and it worked. Thanks! I have no idea what it's not working with the my_planet field. I tested one that just receives integers with a number and it worked in my first try. Maybe some permission problem? I can't find anything in the logs. Just one question. Is this required in the code? $u->of(false); Link to comment Share on other sites More sharing options...
rick Posted May 22, 2017 Share Posted May 22, 2017 4 minutes ago, Thor said: Just one question. Is this required in the code? $u->of(false); Yes. Any time you create or retrieve a page, whether it is a User type or any type of Page object, you should turn off output formatting before you save the data. For example: // new user, or any type of page object $u = new User(); $u->of(false); // turn off output formatting // assign data to fields $u->save(); // existing user, or any type of page ovbect. $u = $users->get("username"); // replace username with the name of a user $u->of(false); // turn off output formatting // assign data to fields $u->save(); ProcessWire will automatically turn output formatting on again after the save completes. 1 Link to comment Share on other sites More sharing options...
Thor Posted May 22, 2017 Author Share Posted May 22, 2017 Thank's Rick. I will research that. Is that production ready or just for debugging? Link to comment Share on other sites More sharing options...
rick Posted May 22, 2017 Share Posted May 22, 2017 1 hour ago, Thor said: Thank's Rick. I will research that. Is that production ready or just for debugging? Do that all the time and you won't go wrong. 1 Link to comment Share on other sites More sharing options...
Thor Posted May 23, 2017 Author Share Posted May 23, 2017 23 hours ago, rick said: Do that all the time and you won't go wrong. Thank you, I will then. 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