View::render PHP Method

render() public method

Render template
public render ( $file, $mime = 'text/html', array $hive = NULL, $ttl ) : string
$file string
$mime string
$hive array array
$ttl int
return string
    function render($file, $mime = 'text/html', array $hive = NULL, $ttl = 0)
    {
        $fw = Base::instance();
        $cache = Cache::instance();
        if ($cache->exists($hash = $fw->hash($file), $data)) {
            return $data;
        }
        foreach ($fw->split($fw->get('UI') . ';./') as $dir) {
            if (is_file($this->view = $fw->fixslashes($dir . $file))) {
                if (isset($_COOKIE[session_name()]) && !headers_sent() && session_status() != PHP_SESSION_ACTIVE) {
                    session_start();
                }
                $fw->sync('SESSION');
                if ($mime && !$fw->get('CLI') && !headers_sent()) {
                    header('Content-Type: ' . $mime . '; ' . 'charset=' . $fw->get('ENCODING'));
                }
                $data = $this->sandbox($hive);
                if (isset($this->trigger['afterrender'])) {
                    foreach ($this->trigger['afterrender'] as $func) {
                        $data = $fw->call($func, $data);
                    }
                }
                if ($ttl) {
                    $cache->set($hash, $data, $ttl);
                }
                return $data;
            }
        }
        user_error(sprintf(Base::E_Open, $file), E_USER_ERROR);
    }

Usage Example

 public function index($room_id)
 {
     $room = $this->Room->getRoomById($room_id);
     $this->set('room', $room);
     if (!empty($room)) {
         $last_update = time();
         $idafter = 0;
         $messages = $this->Message->getMessages($room_id);
         if (!empty($messages)) {
             $messages = array_reverse($messages);
             $idafter = $messages[count($messages) - 1]['Message']['message_id'];
         }
         // Render message list
         $view = new View($this, false);
         $view->layout = false;
         $view->set(compact('messages', $messages));
         $view->viewPath = 'Message';
         $message_list = $view->render('message_list');
         $this->set('message_list', $message_list);
         $this->set('idafter', $idafter);
         $this->set('last_update', $last_update);
         $this->set('title', $room['Room']['name']);
     } else {
         $this->set('title', 'Room not found!');
     }
 }
All Usage Examples Of View::render