wilsea Posted June 1, 2014 Share Posted June 1, 2014 The penny has just dropped that if I use a pagefield I get easy access to all the fields on the pagefield page, so I'm tempted to use page fields instead of storing the $page->id to keep track of related information. I'm not sure about any overhead implications, but I'm guessing that it's just the page-id that is stored in the field and then the information about that page is then retrieved in the background as and when required. I can create new pages with page fields,but I don't seem to be able to update existing page fields... $player = wire('pages')->get($_POST["user_id"] * 1); $level = wire('pages')->get($_POST["level_id"] * 1); // create and save new page $game = new Page(); $game->template = 'game'; $game->name = "temp"; $game->parent = ("/games/"); $game->question_list = $_POST["questions"]; $game->level = $level; $game->player = $player; $game->save(); // change name to one based on the saved name id $game = wire('pages')->get("name=temp"); $game->name = $player->id . "_" . $level->id . "_" . $game->id; $game->setOutputFormatting(false); $game->title = $game->name; $game->save(); //update the player details $player->setOutputFormatting(false); $player->game = $game; // no errors but the field is never updated The above code works fine, except for the last line - $player->game is never updated (from exisiting status of empty) , though $game is correctly created with the appropriate $player. Am I missing something, or just trying to do something that's not really practical. Spoilt for choices in PW Link to comment Share on other sites More sharing options...
adrian Posted June 1, 2014 Share Posted June 1, 2014 A couple of really quick comments. Have you tried saving $player? $player->save(); or $player->save("game"); Also you should use: wire('input')->post->user_id; It's the PW way and apart from looking cleaner it also takes care of any magic quote discrepancies between servers. 1 Link to comment Share on other sites More sharing options...
wilsea Posted June 1, 2014 Author Share Posted June 1, 2014 I'm not sure which forum has the record for fastest and most helpful replies, but this one must be pretty close to top of the list! Under 10 minutes for an answer! I had indeed forgotten to add $player->save() - made all the difference (probably more sleep and less time in front of a screen would help too) Thanks Adrian for the tip about wire('input')->post-> instead of $_POST["stuff"] . 3 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