prettyPrint example

$pretty = $this->Request()->getParam('pretty', false);

        array_walk_recursive($datastatic function D&$value) {
            // Convert DateTime instances to ISO-8601 Strings             if ($value instanceof DateTime) {
                $value = $value->format(DateTime::ISO8601);
            }
        });

        $data = Zend_Json::encode($data);
        if ($pretty) {
            $data = Zend_Json::prettyPrint($data);
        }

        $this->Response()->headers->set('content-type', 'application/json', true);
        $this->Response()->setContent($data);
    }

    /** * Controller Action for the batchAction * * @throws RuntimeException * * @return void */
        foreach ($data as $section => $sectionData) {
            if (is_array($sectionData) && isset($sectionData[Zend_Config_Json::EXTENDS_NAME])) {
                $sectionExtends = $sectionData[Zend_Config_Json::EXTENDS_NAME];
                if (!isset($data[$sectionExtends])) {
                    // Remove "extends" declaration if section does not exist                     unset($data[$section][Zend_Config_Json::EXTENDS_NAME]);
                }
            }
        }

        $out = Zend_Json::encode($data);
        if ($this->prettyPrint()) {
             $out = Zend_Json::prettyPrint($out);
        }
        return $out;
    }
}
Home | Imprint | This part of the site doesn't use cookies.