src/View.php
public function renderJSON($force_echo = true, $region = null)
    {
        try {
            $this->renderAll();

            return json_encode(['success' => true,
                                'message' => 'Success',
                                'atkjs'   => $this->getJS($force_echo),
                                'html'    => $this->template->render($region),
                                'id'      => $this->name, ]);
        } catch (\Exception $exception) {
            $this->_rendered = false;
            $l = $this->add(new self());
            if ($exception instanceof \atk4\core\Exception) {
                $l->template->setHTML('Content', $exception->getHTML());
            } elseif ($exception instanceof \Error) {
                $l->add(new self(['ui' => 'message', get_class($exception).': '.
                                                            $exception->getMessage().' (in '.$exception->getFile().':'.$exception->getLine().')',
                    'error', ]));
                $l->add(new Text())->set(nl2br($exception->getTraceAsString()));
            } else {
                $l->add(new self(['ui' => 'message', get_class($exception).': '.$exception->getMessage(), 'error']));
            }

            return json_encode(['success' => false,
                                'message' => $l->getHTML(), ]);
        }
    }
public function renderJSON($force_echo = true, $region = null)
    {
        try {
            $this->renderAll();

            return json_encode(['success' => true,
                                'message' => 'Success',
                                'atkjs'   => $this->getJS($force_echo),
                                'html'    => $this->template->render($region),
                                'id'      => $this->name, ]);
        } catch (\Exception $exception) {
            $this->_rendered = false;
            $l = $this->add(new self());
            if ($exception instanceof \atk4\core\Exception) {
                $l->template->setHTML('Content', $exception->getHTML());
            } elseif ($exception instanceof \Error) {
                $l->add(new self(['ui' => 'message', get_class($exception).': '.
                                                            $exception->getMessage().' (in '.$exception->getFile().':'.$exception->getLine().')',
                    'error', ]));
                $l->add(new Text())->set(nl2br($exception->getTraceAsString()));
            } else {
                $l->add(new self(['ui' => 'message', get_class($exception).': '.$exception->getMessage(), 'error']));
            }

            return json_encode(['success' => false,
                                'message' => $l->getHTML(), ]);
        }
    }
public function renderJSON ( $ force_echo = true , $ region = null ) { try { $ this -> renderAll ( ) ; return json_encode ( [ 'success' => true , 'message' => 'Success' , 'atkjs' => $ this -> getJS ( $ force_echo ) , 'html' => $ this -> template -> render ( $ region ) , 'id' => $ this -> name , ] ) ; } catch ( \ Exception $ exception ) { $ this -> _rendered = false ; $ l = $ this -> add ( new self ( ) ) ; if ( $ exception instanceof \ atk4 \ core \ Exception ) { $ l -> template -> setHTML ( 'Content' , $ exception -> getHTML ( ) ) ; } elseif ( $ exception instanceof \ Error ) { $ l -> add ( new self ( [ 'ui' => 'message' , get_class ( $ exception ) . ': ' . $ exception -> getMessage ( ) . ' (in ' . $ exception -> getFile ( ) . ':' . $ exception -> getLine ( ) . ')' , 'error' , ] ) ) ; $ l -> add ( new Text ( ) ) -> set ( nl2br ( $ exception -> getTraceAsString ( ) ) ) ; } else { $ l -> add ( new self ( [ 'ui' => 'message' , get_class ( $ exception ) . ': ' . $ exception -> getMessage ( ) , 'error' ] ) ) ; } return json_encode ( [ 'success' => false , 'message' => $ l -> getHTML ( ) , ] ) ; } }
Render View using json format.

@param bool   $force_echo
@param string $region     A specific template region to render.

@throws Exception

@return string
Render View using json format .