Peter Troeger Posted December 13, 2018 Share Posted December 13, 2018 Hi ? I encountered a new problem I don't understand and have been trying to solve for the last few hours. I'm trying to pass a _GET variable to a hook, but maybe the hook is executed before the get variables can be used? This is my code: $jobID = $input->get->job; //$jobID = '1033'; <- when I do it like this, everything works perfectly. $activeJob = $pages->get($jobID); $temp_value = $activeJob->id.' - '.$activeJob->title; echo $temp_value; //outputs expected string '1033 - Job Title' $wire->addHookAfter('InputfieldHidden::render', function($event) use(&$activeJob) { if($event->object->name == 'job_titel_und_nummer') { $temp_value = $activeJob->id.' - '.$activeJob->title; echo $temp_value; //outputs '0 - ', so nothing $event->object->set('value', $temp_value); } }); As always, any help greatly appreciated! Thank you! Peter Link to comment Share on other sites More sharing options...
BitPoet Posted December 13, 2018 Share Posted December 13, 2018 Any change if you remove the ampersand from your use() statement? 1 Link to comment Share on other sites More sharing options...
flydev Posted December 13, 2018 Share Posted December 13, 2018 1 hour ago, Peter Troeger said: $jobID = $input->get->job; $jobID = $wire->input->get->job; More infos : @BitPoet I think he is outside template 1 Link to comment Share on other sites More sharing options...
BitPoet Posted December 13, 2018 Share Posted December 13, 2018 2 minutes ago, flydev said: I think he is outside template Though $input seems to be defined, or the echo before attaching the hook would show a NullPage too. 1 Link to comment Share on other sites More sharing options...
Peter Troeger Posted December 14, 2018 Author Share Posted December 14, 2018 16 hours ago, BitPoet said: Any change if you remove the ampersand from your use() statement? No change. Tried that as well. 16 hours ago, flydev said: $jobID = $wire->input->get->job; More infos : @BitPoet I think he is outside template That's right, I'm in ready.php When I add $wire-> I get the following error: Notice: Trying to get property of non-object. Any other ideas? ? Link to comment Share on other sites More sharing options...
flydev Posted December 14, 2018 Share Posted December 14, 2018 Do you have installed TracyDebugger ? What's your ProcessWire version ? $jobID = 0; $jobID = wire()->input->get->job; bd("wire() : $jobID"); $jobID = 0; $jobID = $wire->input->get->job; bd("$wire : $jobID"); $jobID = 0; $jobID = $input->get->job; bd("$input : $jobID"); Link to comment Share on other sites More sharing options...
Peter Troeger Posted December 14, 2018 Author Share Posted December 14, 2018 @flydev no tracyDebugger installed. My processwire Version is 3.0.121 When I add your code modified like this: $jobID = 0; $jobID = wire()->input->get->job; echo $jobID; $jobID = 0; $jobID = $wire->input->get->job; echo $jobID; $jobID = 0; $jobID = $input->get->job; echo $jobID; every echo outputs the ID correctly (must have had a spelling error before). But still not working in my $wire->addHookAfter('InputfieldHidden::render', function($event) use($jobID) { oh, and it also works fine with addHookProperty. Link to comment Share on other sites More sharing options...
flydev Posted December 14, 2018 Share Posted December 14, 2018 You should install TracyDebugger asap and then replace all your `echo` with `bd($your_var)` call, it will be easily for us to help you and for you to debug your code. Your hook is working fine on my side. Comment this line `// if($event->object->name == 'job_titel_und_nummer') {` and try again. Link to comment Share on other sites More sharing options...
Peter Troeger Posted December 14, 2018 Author Share Posted December 14, 2018 I'll have to try next week. Thanks for the help so far. I'll be back! ? 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