This topic is locked
[SOLVED]

 refer to page in buttons server code

10/13/2020 6:54:57 PM
PHPRunner General questions
M
MikeT author

I probably can0t see the forest for the trees...: trying to make a button reusable: can you somehow detect - in the server code of a button - from which page the button click came?

W
WilliamBDevClub member 10/13/2020

You can read the URL on the server side with parse_url

M
MikeT author 10/14/2020

But then you'd have to work with $_SERVER['HTTP_REFERER'], no?

Anyway, I was just wondering if the button object itself knows its context, i.e. on which page it lives. Or maybe use a pageObj method (if there is) to pass in the page from the "before" code of the button.

Sergey Kornilov admin 10/14/2020

In button's Server event check variables $params["table"] and $params["page"]

Array

(

[buttId] => New_Button8

[rndVal] => 1602687802084

[fieldsData] => Array

(

)
[masterData] => Array

(

)
[masterTable] =>

[table] => categories

[page] => list1

[txt] => Hello

[masterKeys] => Array

(

)
[keys] => Array

(

)
[isManyKeys] => 0

[location] =>

)
M
MikeT author 10/14/2020

Thanks Sergey!
Is this somewhat safe / stable to use? In the sense of surviving future phpr updates/upgrades. Maybe asked differently: would you rather advise agains't its use (because - I think - it's not mentioned in the help docs).

Sergey Kornilov admin 10/14/2020

This is not an official API and you can use it on your own risk. It is unlikely to be changed in the next year or two but may be changed at some point later.
Every time we encounter a new need like this we consider adding an official API to handle this. In this specific case, we are unlikely to do so. While adding the same button to multiple pages is a common need the button that acts differently based on where it is placed is, strictly speaking, not the same button. To add an API we need to see a strong and common need which is not the case here.
There is one more possible workaround here. You can read the current URL or page name in the Javascript ClientBefore event and pass it to the Server event. This will require more work but is more reliable.

M
MikeT author 10/14/2020

Thank you very much for the additional info.