Thor

Is ProcessWire right here?

Recommended Posts

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 !!! >:D

Why is it so hard to find this information?

I gave you an example in my second reply. 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

@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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

  • Like 1

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites
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.

  • Like 1

Share this post


Link to post
Share on other sites

Thank's Rick. I will research that. Is that production ready or just for debugging?

Share this post


Link to post
Share on other sites
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.

  • Like 1

Share this post


Link to post
Share on other sites
23 hours ago, rick said:

Do that all the time and you won't go wrong.

Thank you, I will then.

Share this post


Link to post
Share on other sites

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


  • Recently Browsing   0 members

    No registered users viewing this page.