Y
Y
Yuri Petrashevich2015-04-06 19:16:50
Zend Framework
Yuri Petrashevich, 2015-04-06 19:16:50

Zend Framework 2. How to add hyphens to JSON rendering?

ZF2 renders the page in JSON format, you need to add two characters chr(10) and chr(13) to the end of the JSON string without editing the JsonModel class.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2015-04-08
@BelCoder

Option 1 Set the JsonModel::setJsonpCallback()
callback function Option 2 Write a JsonModel derived class and use it in your application. You will get something like this:

namespace Application\View\Model;

use Zend\View\Model\JsonModel as ZendJsonModel;

class JsonModel extends ZendJsonModel
{
    /**
     * {@inheritDoc}
     */
    public function serialize()
    {
        return (parent::serialize() . "\r\n");
    }
}

Write an event handler MvcEvent::EVENT_RENDER , setting the desired priority, or MvcEvent::EVENT_FINISH . It already modify the result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question