Page 1 of 1

Access LoginStatus variable from API Action

Posted: Sat Aug 06, 2022 12:50 pm
by vuongduongquoc

Hi all. Please help me. I have a global variable $LoginStatus in Page_Rendering. How can i access to this variable and pass it in API Action?

function Page_Rendering()
{
    //Log("Page Rendering");
	global $LoginStatus;
	
	$LoginStatus= $LoginStatus["currentUserName"];

    //Log("Page Rendering");
}
$app->get('/updatetaikhoansocai/{name}', function ($request, $response, $args) {
        $name = $args["name"] ?? null; // Get the input value
        if ($name !== null) {

		global $LoginStatus;
		ExecuteUpdate("UPDATE tbl_nks_employees set filtertaikhoan = '" . AdjustSql($name)."' where Username='".$LoginStatus . "'");

        }
        return $response; // Return Psr\Http\Message\ResponseInterface object 
 });

Re: Access LoginStatus variable from API Action

Posted: Sat Aug 06, 2022 1:27 pm
by mobhar

Are you using v2022? If so, please change:

ExecuteUpdate

to

ExecuteStatement

and try again.


Re: Access LoginStatus variable from API Action

Posted: Sat Aug 06, 2022 1:30 pm
by arbei

vuongduongquoc wrote:

$LoginStatus= $LoginStatus["currentUserName"];

  1. This line overwrite the globl variable $LoginStatus.
  2. If you use Api_Action, you need to login the user yourself, you may use Route_Action instead so you may just use CurrentUserName().