Best Practice Argument/Param Passing to Sprunje


#1

I’m returning results via a Sprunje invoked from a SimpleController. I’d like to pass in parameters and it seems I have two standard choices:

  • Use the $args <-- Populated by UF4 from parsing the URI as per api-routes.php (myid in code below)
  • Use the $params <-- Populated by UF4 with anything after the ? in the URL

I want my sprunje to get them all, should I simply merge both arrays and pass that to my sprunje? Is there a best practice?

My api-routes.php content
$app->get(’/api/bfa/lpd/id/{myid}’, ‘UserFrosting\Sprinkle\UfSprinkleBfa\Controller
\ApiController:apiBfaLpdData’)
->add(‘authGuard’);

My ApiController.php content

public function apiBfaLpdData($request, $response, $args)
{
$params = $request->getQueryParams();
$classMapper = $this->ci->classMapper;
$sprunje = $classMapper->createInstance(‘mysprunje’, $classMapper, $params);
$result = $sprunje->toResponse($response);
return $result;
}

How can I pass the contents of both $args and $params to my sprunje in the most appropriate way?

Thanks in advance for any insight.

Sincerely,
Frank


#2

I’m not sure what you’re trying to do with myid, but an extendQuery may be appropriate?
https://learn.userfrosting.com/database/data-sprunjing#extending-a-sprunje-query

Otherwise, the other options I see are to merge the arrays as you suggested or pass the myid with the rest of the query string.


#3

Thanks for the reply @Amos_Folz, for now I’m simply merging the two arrays and that’s giving me what I need.