On Sun, Mar 24, 2013 at 2:53 PM, Michael Gooden
<[email protected]> wrote:
> I got curious, so I implemented it myself. I have this in my
> Application/module.php onBootstrap() function, however you can place it
> where you wish, as long as you attach the listener to the application's main
> event manager.
>
>         $eventManager        = $e->getApplication()->getEventManager();
>         $eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_FINISH,
> function(\Zend\Mvc\MvcEvent $e) {
>             $response = $e->getResponse();
>             if ($response instanceof \Zend\Http\AbstractMessage) {
>                 $header = new \Zend\Http\Header\ContentType();
>                 $header->value = 'text/html; charset=utf-8';
>                 $response->getHeaders()->addHeader($header);
>             }
>         }, 500);
>
> Let me know if this works out for you.

Thank you very much, but I figured it out myself eventually.
Turns out htere is Response object in the $event, so I did this:

    public function onBootstrap(MvcEvent $e)
    {
        $response = $e->getResponse();
        if ($response instanceof \Zend\Http\Response) {
            $headers = $response->getHeaders();
            if ($headers)
                $headers->addHeaderLine('Content-Type', 'text/html;
charset=UTF-8');
        }


>
> Regards,
>
> Michael Gooden
>
>
> On 24 March 2013 14:13, Michael Gooden <[email protected]> wrote:
>>
>> Hi Ross,
>>
>> I would think a listener somewhere along the MvcEvent flow would be
>> appropriate. Have a look here: http://zendframework2.de/en/cheat-sheet.html
>>
>> Without looking at the code I would suggest trying to attach a listener to
>> MvcEvent::EVENT_FINISH that will grab the response from the event and modify
>> the Content-Type header.
>>
>> If you don't come right swing me a mail and we can work it out together.
>>
>> Regards,
>>
>> Michael Gooden
>>
>>
>> On 24 March 2013 13:07, Ross <[email protected]> wrote:
>>>
>>> Hello
>>>
>>> I noticed in telnet that my server returns:
>>> Content-Type: text/html
>>>
>>> I want it to include charset=utf-8 for every page.
>>>
>>> How can I do that?
>>>
>>> --
>>> List: [email protected]
>>> Info: http://framework.zend.com/archives
>>> Unsubscribe: [email protected]
>>>
>>>
>>
>

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to