Example #1
0
 public static function end_sidebar_section()
 {
     echo "</div>\n";
     \zing\view\Base::active()->end_capture();
 }
Example #2
0
 /**
  * Renders a view
  *
  * We now have a view name, e.g.
  * admin/stories/edit
  *
  * The algorithm to find the correct view is as follows:
  * 1. foreach registered view path $v
  *      append view name to $v
  *      glob for $v.*.*
  *      collect all candidate views
  * 2. extract distinct template types from candidate views
  * 3. run content negotiation algorithm on template types to find best fit
  * 4. find first candidate template with matching type
  * 5. derive view handler
  * 6. instantiate view handler
  * 7. render view
  *     
  * That's quite a lot of work to do.
  *
  * Possible optimisations:
  * 1. caching - keep a map of controller/view candidates
  *    (globbing is the main performance problem; would be enabled in production mode only)
  * 2. if there's only one registered template type and one handler, just assume default
  * 3. callback method can be used to selectively disable content negotiation
  */
 protected function render_view($view_name = null)
 {
     if ($view_name === null) {
         $view_name = $this->action_name;
     }
     $view_name = \zing\view\Base::resolve_relative_view_path($view_name, $this->controller_path);
     $view_paths = \zing\view\Base::candidate_views_for($view_name);
     if (count($view_paths) == 0) {
         throw new \Exception("no template found for view '{$view_name}'");
     }
     $template_types = array();
     foreach ($view_paths as $vp) {
         $base = basename($vp[1]);
         $p1 = strpos($base, '.');
         $p2 = strrpos($base, '.');
         $tt = substr($base, $p1 + 1, $p2 - $p1 - 1);
         if (!in_array($tt, $template_types)) {
             $template_types[] = $tt;
         }
     }
     $template_type = $this->negotiate_template_type($template_types);
     foreach ($view_paths as $view_path) {
         if (strpos($view_path[1], ".{$template_type}.") !== false) {
             break;
         }
     }
     $handler_ext = substr($view_path[1], strrpos($view_path[1], '.') + 1);
     if (!isset(self::$view_handlers[$handler_ext])) {
         throw new \Exception("no registered view handler for .{$handler_ext}");
     }
     $handler_class = self::$view_handlers[$handler_ext];
     $handler = new $handler_class();
     $handler->set_template_type($template_type);
     $handler->import_from_controller($this);
     $this->response->set_body($handler->render_view($view_name, $view_path[0]));
 }
Example #3
0
 public static function pager($collection = null)
 {
     return \zing\view\Base::active()->render_partial(':pager', array('collection' => $collection));
 }