nicl
nicl

Reputation: 41

Set custom Content-Type in Joomla Framework

I am using the Joomla framework API to build a web application. Now I want to display some data from the database in JSON format and I have to change the default HTTP-Content-Type from text/html to application/json. The Joomla framework comes with the Symfony HTTP foundation component, so I've searched the web and found this:

use Symfony\Component\HttpFoundation\Response;
$response = new Response();
$response->headers->set('Content-Type', 'application/json');
$response->send();

But there is no effect.

I have also tried the standard way:

header("Content-Type: application/json");

That doesn't work too..

Thanks for any advice!

Upvotes: 2

Views: 533

Answers (2)

nicl
nicl

Reputation: 41

I found the following solution:

In \Joomla\Application\AbstractWebApplication I wrote a new method that sets the existing attribute mimeType:

public function setMimeType($mimeType) {
            $this->mimeType = $mimeType;
        }

This works perfectly.

Upvotes: 1

user4345221
user4345221

Reputation:

Check the JApplicationWeb API and the setHeader / sendHeader functions.

Upvotes: 0

Related Questions