Jan Romero Posted December 7, 2021 Share Posted December 7, 2021 closing ] is in the wrong place 1 Link to comment Share on other sites More sharing options...
Flashmaster82 Posted December 7, 2021 Author Share Posted December 7, 2021 Any suggestions? Link to comment Share on other sites More sharing options...
Flashmaster82 Posted December 7, 2021 Author Share Posted December 7, 2021 $page->setAndSave([ 'title' => "($id) $template_label | $address, $ort", 'name' => "$id $template_label $address $ort", 'noHooks' => true ]); This should be correct but not working https://processwire.com/api/ref/page/set-and-save/ Link to comment Share on other sites More sharing options...
Flashmaster82 Posted December 7, 2021 Author Share Posted December 7, 2021 Fatal Error: Uncaught Error: Maximum function nesting level of '256' reached, aborting! in E:\Wamp\www\Website\wire\core\Fieldgroup.php:81 #0 E:\Wamp\www\Website\wire\core\Fieldgroup.php(81): is_int('language') #1 E:\Wamp\www\Website\wire\core\Fieldgroup.php(242): Fieldgroup->isValidKey('language') #2 E:\Wamp\www\Website\wire\core\Page.php(1261): Fieldgroup->getField('language') #3 E:\Wamp\www\Website\wire\core\Page.php(1471): Page->getField('language') #4 E:\Wamp\www\Website\wire\core\User.php(451): Page->getFieldValue('language', '') #5 E:\Wamp\www\Website\wire\core\Page.php(1221): User->getFieldValue('language') #6 E:\Wamp\www\Website\wire\core\Page.php(1846): Page->get('language') #7 E:\Wamp\www\Website\wire\core\PageFinder.php(2070): Page->__get('language') #8 E:\Wamp\www\Website\wire\core\PageFinder.php(1695): PageFinder->getQuerySortSelector(Object(Database (line 81 of E:\Wamp\www\Website\wire\core\Fieldgroup.php) This error message was shown because: you are logged in as a Superuser. Error has been logged. $wire->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments[0]; if (!$page->matches('template=dashboard_services_bathroomrenovation_servicepage|dashboard_services_demolition_servicepage|dashboard_services_extension_servicepage|dashboard_services_recycling_servicepage|dashboard_services_totalrenovation_servicepage')) return; $id = $page->id; if ($page->customer_project_address === 0) { $address = $page->parent->address; $ort = $page->parent->ort->title; } else if ($page->customer_project_address === 1) { $address = $page->address; $ort = $page->ort->title; } $template_label = $page->template->label; $page->setAndSave([ 'title' => "($id) $template_label | $address, $ort", 'name' => "$id $template_label $address $ort", 'noHooks' => true ]); }); Link to comment Share on other sites More sharing options...
Jan Romero Posted December 7, 2021 Share Posted December 7, 2021 Come on, man, you can do this ? That’s the same error message from before. Also, like I said, I’m pretty sure you just had to move the one ] to a different place. The number of brackets was correct. I haven’t been on the computer much today. I can look at the language stuff tomorrow, if you want. Btw a good “trick” is to just skim the actual source code of PW methods. I often find the docs a little lacking, unfortunately. Ryan’s code is quite readable, and usually one is only interested in what happens to the arguments, where best to hook etc. Somewhat superficial stuff like that, if you will, so it’s not too bad. For example, it seems your code is mixing up the fielname/value array and the options array when calling setAndSave(). PW functions often takes multiple different types in multiple different places, which can be a blessing and a curse. 1 Link to comment Share on other sites More sharing options...
Flashmaster82 Posted December 7, 2021 Author Share Posted December 7, 2021 Well im lost ? This is my current code $page->setAndSave([ 'title' => "($id) $template_label | $address, $ort", 'name' => "$id $template_label $address $ort", 'noHooks' => true ]); and its exactly like in the docs..? https://processwire.com/api/ref/page/set-and-save/ Link to comment Share on other sites More sharing options...
Jan Romero Posted December 7, 2021 Share Posted December 7, 2021 No, because unfortunately the docs don’t show an example with multiple fields and the options array. I may be wrong and it’s a little difficult to see on mobile, but I would say it needs to be two separate arrays, like this: 12 minutes ago, Flashmaster82 said: $page->setAndSave([ 'title' => "($id) $template_label | $address, $ort", 'name' => "$id $template_label $address $ort"], ['noHooks' => true ]); Link to comment Share on other sites More sharing options...
Flashmaster82 Posted December 7, 2021 Author Share Posted December 7, 2021 That caused the same error.. hmm 1 Link to comment Share on other sites More sharing options...
Jan Romero Posted December 8, 2021 Share Posted December 8, 2021 Indeed… Like I said, the code is the best documentation. So I guess it’s $page->setAndSave( [ 'title' => "($id) $template_label | $address, $ort" , 'name' => "$id $template_label $address $ort" ] , null , [ 'noHooks' => true ]); 1 Link to comment Share on other sites More sharing options...
Flashmaster82 Posted December 8, 2021 Author Share Posted December 8, 2021 That worked! Yaay. Thanks. I´m only a beginner at php, so it´s not that easy for me ? 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