data-response icon indicating copy to clipboard operation
data-response copied to clipboard

Is there a way to return raw data from a controller?

Open viktorprogger opened this issue 1 year ago • 1 comments

E.g. to return ['foo' => 'bar'] instead of

return $this->dataResponseFactory->create(['foo' => 'bar']);

In case it is, let's add corresponding configs and all the related code to documentation.

viktorprogger avatar Jan 01 '25 16:01 viktorprogger

final class ApiController
{
    public function actionIndex(DataResponseFactory $responseFactory)
	{
        $data = ['name' => 'Alex'];
        return $responseFactory->createResponse($data);
	}
}

Given FormatDataResponse is in your stack, you'll get the formatted object as output.

samdark avatar Jan 01 '25 19:01 samdark