Ejemplo n.º 1
0
 public function render(View $view)
 {
     switch ($this->getViewType()) {
         case Action::VIEW_HTML:
             $this->render = new \ORC\MVC\Response\HTML($this->controller);
             break;
         case Action::VIEW_JSON:
             $this->render = new \ORC\MVC\Response\JSON($this->controller);
             break;
         case Action::VIEW_RAW:
             $this->render = new \ORC\MVC\Response\RAW($this->controller);
             break;
         case Action::VIEW_REDIRECT:
             //redirect already be handled in controller, so here should not be this option
             //break;
         //redirect already be handled in controller, so here should not be this option
         //break;
         default:
             throw new ViewNotFoundException('unknown view type from action');
             break;
     }
     ViewModel::getInstance()->registerAll();
     //load all data from model
     $this->content = $view->render();
     return $this->render->render();
 }
Ejemplo n.º 2
0
 public function render()
 {
     //add default raw js
     $viewModel = ViewModel::getInstance();
     $js = 'function site_config(key) {return {"base_url":"' . Config::getInstance()->get('main_server') . '","window_id":' . mt_rand(1, 1000000) . '}[key.toLowerCase()];}';
     $viewModel->addRawJs($js);
     $action = $this->_controller->getAction();
     //find the correct template
     $template = TemplateManager::getInstance()->findTemplate($action);
     return $template->render();
 }
Ejemplo n.º 3
0
 private function prepareReservedVariable($name)
 {
     $output = '';
     $cache_buster = Config::getInstance()->get('template.cache_buster');
     if ($cache_buster == '') {
         $cache_buster = \ORC\Util\Util::getNow();
     }
     switch ($name) {
         case 'js':
             //first get the template js
             $existing_jses = array();
             $jses = array_merge($this->_jses, $this->getViewModel()->getAllJs());
             //pre($jses, $this->_jses);
             foreach ($jses as $path) {
                 if (in_array($path, $existing_jses)) {
                     continue;
                 }
                 $existing_jses[] = $path;
                 $path = Url::getFullHttpPath($path);
                 $output .= sprintf('<script type="text/javascript" src="%s?%s"></script>', $path, $cache_buster);
             }
             break;
         case 'css':
             $existing_csses = array();
             $csses = array_merge($this->_csses, $this->getViewModel()->getAllCss());
             foreach ($csses as $css) {
                 if (!isset($existing_csses[$css['media']])) {
                     $existing_csses[$css['media']] = array();
                 }
                 if (in_array($css['path'], $existing_csses[$css['media']])) {
                     continue;
                 }
                 $existing_csses[$css['media']][] = $css['path'];
                 $css['path'] = Url::getFullHttpPath($css['path']);
                 $output .= sprintf('<link type="text/css" rel="stylesheet" href="%s?%s" media="%s" />', $css['path'], $cache_buster, $css['media']);
             }
             break;
         case 'raw_js':
             $output .= implode("\n", $this->_viewModel->getRawJs());
             break;
         case 'raw_css':
             $output .= implode("\n", $this->_viewModel->getRawCss());
             break;
         case 'title':
             $output .= $this->getViewModel()->getTitle();
             break;
     }
     return $output;
 }
Ejemplo n.º 4
0
 protected function getViewModel()
 {
     return ViewModel::getInstance();
 }