This topic is locked
[SOLVED]

How to change the url to follow when a details link on a List page is clicked

11/14/2022 5:01:01 AM
PHPRunner General questions
H
Henny Sol author

I have two tables: CostTypes and Costs. The Costs table contains a date field (the date on which the costs payment has been done).

On the List page of the CostTypes table there is a details link to the List page of the Costs table.

On the List page of the Costs table there is a filter panel (the costs can be filtered on the year on which the costs payment has been done).

When I click on the details link on the List page of the CostTypes table I want to see only the Costs paid in the current year.

Problem is that the List page of the Costs is not a menuItem. If it was a menuItem I could edit the url-to-use in the ModifyMenuItem event:

$yr = date("Y");
$filter = "f=year~equals~" . $yr . ")";
$menuItem->SetParams($filter);

So far I have not been able to find the place where I can change the url to what I want (including the "f=year~equals..." clause).
I did try to redirect to the url I want but so far I only produced the error "too many redirects".

So: where can I change the url to follow when a details link on a List page is clicked?

Regards,

Henny Sol

admin 11/14/2022

Redirect is a correct idea but you need to make sure you only do it once. Do not redirect if your filter parameter already presents in the URL and it will solve the issue.

H
Henny Sol author 11/14/2022

I inserted the redirect in the BeforeProcessList event of the Listpage of Costs. But how can I know if it's the first redirect or not. If I could see in the BeforeProcessList what the current url is I would know. So: how to retrieve the current url?

admin 11/14/2022

Plenty of information comes when you search Google for "php get current page url". Check this article for instance:
https://stackoverflow.com/questions/6768793/get-the-full-url-in-php

H
Henny Sol author 11/15/2022

I placed the following code in the BeforeProcessList of my List page:

//** Redirect to another page ****
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if (!strpos($actual_link,"jaar~equals")) {
$jr = date("Y");
header("Location:kosten_list.php?f=(jaar~equals~" . $jr . ")&mastertable=KostenType&masterkey1=1");
exit();
}

Works lik a charm. Thank you, admin!