REST API: Undefined Array Key

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

REST API: Undefined Array Key

Post by Niijimasama »

I created the API action below: (v2024)

$app->get('/GetEmpInfo[/{uno}]', function ($request, $response, $args) {
        $uno = $args["uno"] ?? null;
        if ($pfno !== null) {
			$sql = "select * from employees where pfno = ".$uno;
            $info = ExecuteRow($sql);            
        }else{
            $info = (0);
        }	
		return $response->withJson($info);
    });

On running via URL: http://localhost/myapp/api/getempinfo/2
it returns a value of zero i.e. it does not pick the 2.
When I put an echo statement to determine the value of $args["uno"] , I get the error undefined array key.

I have no idea what I am missing.
Any help would be highly appreciated.


arbei
User
Posts: 9384

Post by arbei »

Make sure you use the same lettercase for the action name ("GetEmpInfo" vs. "getempinfo").


Niijimasama
User
Posts: 85

Post by Niijimasama »

Thanks for the response.
I get the same error i.e. Undefined array key.

UPDATE
I changed some advanced settings and it just worked. Don't know which exact one it it but they are:

  1. Unchecked "Use Route Cache".
  2. Unchecked "Generate Production config file".
  3. Checked "Generate Route Groups".

Will test further to see which what caused it to work.


arbei
User
Posts: 9384

Post by arbei »

It should be 1. After changing routes, you need to remove old cache. See Use route cache:
Notes:
1. When enabled, the cache will be compiled once and never be regenerated again.
2. When you deploy new versions of your scripts (for example, after adding or deleting a table) to production, you must delete the generated file (<ProjectFolder>/<LogFolder>/cache/RouteCache.php) to ensure that the cache will be re-compiled.


Post Reply