Esempio n. 1
0
 public function process_response()
 {
     if (!rtConfig::get('enable_toolbar', false)) {
         return;
     }
     $params = array('logs' => rtLogger::getLogs());
     $params = array_merge($params, rtController::getMagicViewVars());
     list($tpl, $view_class) = findTemplateFileName(rtConfig::get('rt_core_dir') . DS . 'default' . DS . 'toolbar');
     $toolbar = new $view_class($tpl, $params);
     $response = rtResponse::getInstance();
     $new_body = str_replace('</body>', $toolbar->getOutput() . '</body>', $response->getBody());
     $response->setBody($new_body);
 }
Esempio n. 2
0
 public function execute($component, $func, $vars = array())
 {
     $func_up = ucwords($func);
     $real_func = "execute{$func_up}";
     if (!method_exists($this, $real_func)) {
         throw new Exception("Function: '{$real_func}' doesn't exist in component:" . get_class($this));
     }
     // call the component function
     call_user_func(array($this, $real_func));
     // render view
     $this->_template_ = APP_DIR . DS . 'views' . DS . 'components' . DS . $component . DS . "_{$func}";
     list($file, $view_class) = findTemplateFileName($this->_template_);
     // merge the use defined vars
     $view = new $view_class($file, array_merge($this->_view_vars_, $vars, $this->getMagicViewVars()));
     return $view->getOutput();
 }
Esempio n. 3
0
/**
 * Include partial to the view
 * No need to explict echo the result of partial_include
 * It behavors like php include, borrowed from symfony
 * 
 * include_partial("index/apache");
 *
 * @param string $partial
 * @param array  $params
 */
function include_partial($partial, $params = array())
{
    $request = mfRequest::getInstance();
    $format = $request->getParameter('format', 'html');
    $array = explode('/', $partial);
    $count = count($array);
    $partial = '_' . $array[$count - 1];
    // all partials start with '_'
    $formated_partial = '_' . $array[$count - 1] . ".{$format}";
    unset($array[$count - 1]);
    // pop up partial file name
    $path = implode('/', $array);
    // reconnect to the path
    // specify certain controller to render
    if ($path) {
        $view_path = VIEWS_DIR . DS . $path;
    } else {
        $view_path = VIEWS_DIR . DS . $request->getController();
    }
    list($view_tpl, $view_class) = findTemplateFileName($view_path . DS . $partial);
    $view = new $view_class($view_tpl, $params);
    // before output ob_start have stop direct output to browse, so we echo but no return string
    echo $view->display();
}
Esempio n. 4
0
 protected function render()
 {
     // Magic view variables
     $magic_vars = self::getMagicViewVars();
     // merge
     $this->_view_vars_ = array_merge($magic_vars, $this->_view_vars_);
     $this->_layout_vars_ = array_merge($magic_vars, $this->_layout_vars_);
     list($template, $view_class) = findTemplateFileName($this->getTemplateDir() . DS . $this->getTemplate());
     $view = new $view_class($template, $this->_view_vars_);
     // render layout
     if ($this->_layout_) {
         // content here
         $this->_layout_vars_['mf_layout_content'] = $view->getOutput();
         list($layout_file, $layout_class) = findTemplateFileName($this->getLayoutDir() . DS . $this->getLayout());
         $layout = new $layout_class($layout_file, $this->_layout_vars_);
         mfResponse::getInstance()->setBody($layout->getOutput());
     } else {
         // no layout
         mfResponse::getInstance()->setBody($view->getOutput());
     }
 }
Esempio n. 5
0
function exception_handler(Exception $e)
{
    //	ob_clean();
    ob_start();
    echo "<div id=\"msg\">" . $e->getMessage() . "</div>";
    echo "<pre>" . $e->getTraceAsString() . "</pre>";
    echo "<hr /> Vars:<br /><pre>" . var_dump(rtRequest::getInstance()) . "</pre>";
    $content = ob_get_clean();
    // findTemplateFileName may throw exception, but PHP5.2.5 can't handle this
    try {
        list($file, $view_class) = findTemplateFileName(RT_CORE_DIR . DS . 'default' . DS . 'layout');
        $view = new $view_class($file, array('rt_layout_content' => $content));
        $view->display();
    } catch (Exception $e_in) {
        echo $content . "<hr />";
        echo "<div>" . $e_in->getMessage() . "</div>";
        echo "<pre>" . $e_in->getTraceAsString() . "</pre>";
    }
}