Jump to content

Populating a page selector with a logged in user id using ready.php hook


cb2004
 Share

Recommended Posts

I am building a system which has a page selector using the template user. When the page is added I wish to autopopulate the page_user field with the logged in user, but they can also change this should they wish. This doesnt seem to work:

$pages->addHookAfter("added", function($event) {
	$page = $event->arguments(0);

	if ($page->template->id == 57) {
		$page->setAndSave("page_user", $user);
	}
}

I have also tried numerous other things like $page->page_user = $user, and lots of variations but no joy. What does actually work is something like $page->setAndSave("page_user", 41); so its not reading the logged in $user, even if I do something like $user->id.

Any help would be appreciated.

Cheers.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...