Using custom file

Hi,
v2023strange things happening with a custom file that is generated. funny thing is exact file in terms of setup dashboard.php the functions work correctlythe file in question fetchdashboarddata.php - which is called from the dashboard.php file as a $.ajax callthe generated code:

<?php

namespace PHPMaker2023\accTrack2;

// Page object
$$FetchDashboardData= &$Page;
?>
<?php
$Page->showMessage();
?>

$Page->showMessage(); <<<==== errors out


Fatal error: Uncaught Error: Call to a member function showMessage() on null in C:\xampp\htdocs\acctrack-2023-sa\views\FetchDashboardData.php:9
Stack trace:
#0 {main}
thrown in C:\xampp\htdocs\acctrack-2023-sa\views\FetchDashboardData.php on line 9
as well:
removing showMessage() to conitnue, and trying to get global $Security object for exampleglobal $Security <<<<<=== returns a null objectI tried to rung FetchDashboardData.php on its own and it errors out as noted above. other functions are not available as well like any DB functions. It’s as if the common files are not available.

If i manually add the files

$RELATIVE_PATH = "../";

// Require files
require_once $RELATIVE_PATH."vendor/autoload.php";
require_once $RELATIVE_PATH."src/constants.php";
require_once $RELATIVE_PATH."src/config.php";
require_once $RELATIVE_PATH."src/phpfn.php";
require_once $RELATIVE_PATH."src/userfn.php";

the DB and other functions are available, nut still the Security object is null and its in a “not logged in”/anonymous statethe file is located on the views folder just like the other custom files.so, I can’t figure out why this file is any different that the other 3 custom files that I have and that were generatedThanks

ok so it looks like i can’t call FetchDashboardData.php in the ajax function

$.ajax({
  url: './views/FetchDashboardData.php',
  type: 'POST',
  success: function(data1){
    var data = $.parseJSON(data1);

in the address bar ifi entered fetchdata - it behaved correctly
I tried changing the url: to ‘/fetchdata’, but doesn’t workanyway to call this file via an ajax call ?

sticcino wrote:

$$FetchDashboardData= &$Page;

Why two “$$”? Do not use “$” in your file name of the Custom File. “$” means variable in PHP, $$FetchDashboardData means a variable variable, the value is null in your case.Avoid using Custom File as URL of Ajax action, (you also should not call a page by its physical file name,) you may read Using Route_Action server event.

hi,sorry that was a typo…i modified the code:

function fetchdata(){
    loadjs.ready("head", function() {

          $.get(ew.getApiUrl("fetchDashBoardData"))
        .done(function (msg) {
            ew.alert('success');
        }).fail(function (msg) {
            ew.alert("Error");
        });       
    });

and created corresponding:
$app->get(‘/fetchDashBoardData’, function ($request, $response, $args) {}added my code to that and is working perfectly!thanks