protected function composeView($scope = '', $data = array(), $template = '', $extension = '')
    {
        if (!is_array($data)) {
            $data = [];
        }

        if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) {
            $this->returnJson([
                'success' => true,
                'data' => $data,
            ]);
        } else {
            foreach ($data as $key => $value) {
                if (is_array($value) || is_object($value)) {
                    $data[$key] = json_encode($value);
                }
            }
            $this->setData('data', $data);
            $this->setPage($scope, $template, $extension);
        }
    }
protected function composeView($scope = '', $data = array(), $template = '', $extension = '')
    {
        if (!is_array($data)) {
            $data = [];
        }

        if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) {
            $this->returnJson([
                'success' => true,
                'data' => $data,
            ]);
        } else {
            foreach ($data as $key => $value) {
                if (is_array($value) || is_object($value)) {
                    $data[$key] = json_encode($value);
                }
            }
            $this->setData('data', $data);
            $this->setPage($scope, $template, $extension);
        }
    }
protected function composeView ( $ scope = '' , $ data = array ( ) , $ template = '' , $ extension = '' ) { if ( ! is_array ( $ data ) ) { $ data = [ ] ; } if ( isset ( $ _SERVER [ 'HTTP_ACCEPT' ] ) && strpos ( $ _SERVER [ 'HTTP_ACCEPT' ] , 'application/json' ) !== false ) { $ this -> returnJson ( [ 'success' => true , 'data' => $ data , ] ) ; } else { foreach ( $ data as $ key => $ value ) { if ( is_array ( $ value ) || is_object ( $ value ) ) { $ data [ $ key ] = json_encode ( $ value ) ; } } $ this -> setData ( 'data' , $ data ) ; $ this -> setPage ( $ scope , $ template , $ extension ) ; } }
Main method to render a view using a particular template.
Detects whether the client only need JSON content.
You still need to set the main view, however it must be set
before to call this method as this view may be overridden.

@param string [$scope] - A CSS class name that scope the view
@param array [$data] - An optional data set to forward to the view
@param String [$template] - Defines the path of the view, default to 'pages/index.tpl'
@param String [$extension] - Defines the extension that should contain the template
@throws \common_exception_Error
Main method to render a view using a particular template . Detects whether the client only need JSON content . You still need to set the main view however it must be set before to call this method as this view may be overridden .