Reflexa Posted September 11, 2017 Posted September 11, 2017 Hello, I've got users this way: user01 user02 ... user99 And I've got a template "Verkaeufergruppen" with the fields "title" and "bezei" this way 01 Adams 02 Brown 03 Smith The rule is: user01 = 01 Adams, user02 = 02 Brown. When a new page with the template "Bericht" is created: The field "ADM_Name" (=text) should be set automatically to "Adams" if user01 has created the page. That's why I use the PHP function substr, so user01 --> 01, user02 --> 02, ... I made a hook in ready.php: $wire->addHookAfter('Pages::saveReady', function($event) { $page = $event->arguments(0); if($page->template != "Bericht") return; $admnr = substr($user->name, 4, 2); $admname = $pages->findOne("template=Verkaeufergruppen, title=$admnr")->bezei; if(trim($page->ADM_Name) == '') $page->ADM_Name = $admname; But it doesn't work. I seems it's not possible to take "$user->name". Perhaps somebody can help Many thanks.
adrian Posted September 11, 2017 Posted September 11, 2017 You're running into PHP scope issues. You will need to use: $this->wire('user')->name; Same goes for $pages - use: $this->wire('pages')->findOne ....... 1 1
szabesz Posted September 11, 2017 Posted September 11, 2017 Here is a related very good post I keep recommending from time to time. 2
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