Managing path in Master Detail (v2022)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
gargiulo
User
Posts: 49

Managing path in Master Detail (v2022)

Post by gargiulo »

I'm working with 2 tables: Master A and Detail B . The table B is also at menu as normal entry

i made a very simple custom script to see a PDF document stored (as name , e.g. document1.pdf) in a field of table B. The document has been stored in dedicated folder according with the setup field .

In addition i implemented also a new option in list options just to see the pdf document , to do this i used the events ListOption_Load and ListOptions_Rendered in LIst Page events of the table B. The php file invoked by the script is very simple and stored in the folder customphp created under the main path of the website.
The ListOptions_Rendered event has a below construct :

$this->ListOptions->Items["Vedi Documento"]->Body = "<a href='customphp/VedoPDF.php?id=$Doc_id' target='_blank' ><span>Vedi Documento</span></a>";

when i select table B from the main menu it recognizes correctly the option and if i click on the option VedoPDF.php is launched
Differently if i reach table B using Master Detail View option from table A the list Option doesn't apperas in the row and this is the first bug i experienced

In addition i have a stonger bug which i'm not able to overcome:
the field document in table B has been customized in PHP Maker using Cutom View Tag and it is :

<?php
if (urlencode(CurrentPage()->documento->CurrentValue) != "") {?>
<a target= "_blank" href="customphp/VedoPDF.php?id=<?php echo '../Documenti/Parrocchie/Incontri/' . urlencode(CurrentPage()->documento->CurrentValue) ?>">Click per Vedere/Ristampare il documento</a>
<?php
}?>

it means that when i view the record and i click on the link i launch the same VedoPDF.php

It runs perfectly when i reach the row from table B as normal entry at the menu, but when i reach the row from Master Detail View from table A it doesn't run due to the fact that the path is different. Just to identify what happens :

  • in the first case the path you see on the screen when i put the cursor on the field is
    localhost/Caritas/customphp/VedoPDF.php?id=...........
    and it is correct
  • in the second case the path you see is :
    localhost/Caritas/ParrocchieView/customphp/VedoPDF.php?=.......
    and this is wrong and i receive the error 404
    of course the Master Table is Parrocchie and it seems be a folder

do you have some suggestions to offer in order to bypass two bugs

thanks in advance


arbei
User
Posts: 9384

Post by arbei »

You should use a absolute path in your code, e.g.

href='/Caritas/customphp/VedoPDF.php?...'

gargiulo
User
Posts: 49

Post by gargiulo »

Thanks it runs but what will happens when i export the project in my website which has a diferent name ("Caritas" is a production folder while the official is different)

What about my first bug (see the first message)

Thanks again


arbei
User
Posts: 9384

Post by arbei »

  1. You may use GetUrl("your path") to add the base path,
  2. Each table (master and detail tables) has its own $ListOptions property, your code only applies to the table that you added your server event to.

gargiulo
User
Posts: 49

Post by gargiulo »

thanks for the #1: i did

about #2, i have to say, sorry, that i don't understand what you wrote, it is unclear to me. May i ask you to address me better

thanks again


arbei
User
Posts: 9384

Post by arbei »

gargiulo wrote:

to do this i used the events ListOption_Load and ListOptions_Rendered in List Page events of the table B

In Master/Detail-View, the page of the detail table is the Detail Grid page, not the List page. If you add code to the List page, your code only applies to the List page of the detail table.


gargiulo
User
Posts: 49

Post by gargiulo »

Thanks a lot it runs.
May i ask for one additional trouble still regarding Master/Detail.

i customized the Custom View Tag of field in table B with the below code :

<?php
//if ($this->PageID() != "grid") {
//if (CurrentPage()->getCurrentMasterTable()== "") {
// if (CurrentPage()->getCurrentDetailTable()=="parrmeet" {} else {
if (urlencode(CurrentPage()->documento->CurrentValue) != "") {?>
<a target= "_blank" href="<?php echo GetUrl('customphp')?>/VedoPDF.php?id=<?php echo '../Documenti/Parrocchie/Incontri/' . urlencode(CurrentPage()->documento->CurrentValue) ?>">Click per Vedere/Ristampare il documento</a>
<?php
}
//}

as you can see there are a lot of line in comment due to my tentatives to solve the issue. What happens :

  • if list the table B from the main menu as normal table the field is listed correctly and i can launch the VedoPDF.php
  • if i select the main table A and try to see the Master/Detail A/B i receive an error in the field list which is " Warning: Attempt to read property "Current Value" on null.........."
    I tried to bypass the problem using different conditions (see line in comment) w/o results. is there way to avoid the Custom View Tag code in case of Master/Detail or may you suggest a different coding

arbei
User
Posts: 9384

Post by arbei »

If you use PHP 8, you should use ?->, see Nullsafe methods and properties.


gargiulo
User
Posts: 49

Post by gargiulo »

great thanks !!!!


Post Reply