Calling global function to API

if I want call a global function from ‘phpfn’ to the API action , I got API internal error and Can’t find the error case even in log files
so I thought I am not writing the wright syntax, any way here what I have try :

  $app->get('/Sections/{name}', function ($request, $response, $args) {
        $action = $args["name"] ?? null; // Get the input value 
        if ($action !== null) {
            $fetch_rander = Conn()->executeQuery("SELECT* FROM departments")->fetchAll();
            $body = array();
            $record_count = Count($fetch_rander);
            $basepath = BasePath();
            if ($record_count > 0) {
                foreach ($fetch_rander as $row) {
                    $section_title = $row[$action."_section_name"];
                    $section_image = $row["image"];
                    $imageUrl = GetImageViewTag("image",$section_image);
                    $body[] = array("
                         <div class='column'>
                           <a href='ProductsList'>
                             <div class='card'>
                               <div class='section-img'>
                                 $imageUrl
                               </div>
                              </div>
                            </a>
                         </div>
                    ");
                }
                   }
        return $response->withJson($body);
        });

the error cased after i add ‘GetImageViewTag()’ function
any idea , Thanx

It seems you want to display the content in a HTML format that some part of it was derived from database, right?If so, perhaps you may try How to Load Data from Database into Custom Files (v2022)

Even the code is for Custom Files, however you may get the similar logic on how to get values through loop of recordset.

rembo wrote:

$imageUrl = GetImageViewTag(“image”,$section_image);
the error cased after i add ‘GetImageViewTag()’ function

That is because your arguments are wrong. From the source code, the function is: (v2022)

// Get image view tag
function GetImageViewTag(&$fld, $val)

where $fld is the field object and $val is the ViewValue of the field.

arbei wrote:

where > $fld > is the field object and > $val > is the ViewValue of the field.

so it well be

GetSectionsViewTag(Container('departments')->image, $row["image"]);

Note GetSectionsViewTag() is same GetImageViewTag() i just edit the html tagbut Unfortunately now i get empty tag not an error ,don’t know why in the console i can see the image tag work fine but give me empty tag,
so i have followed mobhar way
Thanx

If “image” is file upload field, GetImageViewTag() won’t work, it is not for file upload fields.