public function encodeOutput($data)
    {
        // TODO - use HTTP_ACCEPT here ?
        //var_dump($_SERVER['HTTP_ACCEPT']);

        if ($_GET['format'] == 'xml') {
            throw $this->exception('only JSON format is supported', null, 406);
        }

        if ($_GET['format'] == 'json_pretty') {
            header('Content-type: application/json');
            echo json_encode($data, JSON_PRETTY_PRINT);
            return;
        }

        if ($_GET['format'] == 'html') {
            echo '<pre>';
            echo json_encode($data, JSON_PRETTY_PRINT);
            return;
        }

        header('Content-type: application/json');

        if ($data === null) {
            $data = array();
        }
        echo json_encode($data);
    }
public function encodeOutput($data)
    {
        // TODO - use HTTP_ACCEPT here ?
        //var_dump($_SERVER['HTTP_ACCEPT']);

        if ($_GET['format'] == 'xml') {
            throw $this->exception('only JSON format is supported', null, 406);
        }

        if ($_GET['format'] == 'json_pretty') {
            header('Content-type: application/json');
            echo json_encode($data, JSON_PRETTY_PRINT);
            return;
        }

        if ($_GET['format'] == 'html') {
            echo '<pre>';
            echo json_encode($data, JSON_PRETTY_PRINT);
            return;
        }

        header('Content-type: application/json');

        if ($data === null) {
            $data = array();
        }
        echo json_encode($data);
    }
public function encodeOutput ( $ data ) { // TODO - use HTTP_ACCEPT here ? //var_dump($_SERVER['HTTP_ACCEPT']); if ( $ _GET [ 'format' ] == 'xml' ) { throw $ this -> exception ( 'only JSON format is supported' , null , 406 ) ; } if ( $ _GET [ 'format' ] == 'json_pretty' ) { header ( 'Content-type: application/json' ) ; echo json_encode ( $ data , JSON_PRETTY_PRINT ) ; return ; } if ( $ _GET [ 'format' ] == 'html' ) { echo '<pre>' ; echo json_encode ( $ data , JSON_PRETTY_PRINT ) ; return ; } header ( 'Content-type: application/json' ) ; if ( $ data === null ) { $ data = array ( ) ; } echo json_encode ( $ data ) ; }
Output will be properly fromatted.

@param mixed $data
Output will be properly fromatted .