Show
Ignore:
Timestamp:
03/14/06 03:21:43 (6 years ago)
Author:
john
Message:

added render functionality to AR

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/action_controller.php

    r175 r176  
    203203     */ 
    204204    private $action_render_performed = false; 
     205 
     206    /** 
     207     *  @todo Document this attribute 
     208     */ 
     209    private $action_called = false; 
    205210 
    206211    /** 
     
    532537        # If controller is loaded then start processing            
    533538        if($this->loaded) { 
     539             
    534540            include_once($this->controller_file); 
    535541            if(class_exists($this->controller_class, false)) { 
     542                 
    536543                $class = $this->controller_class; 
    537544                $this->controller_object = new $class(); 
     545                 
    538546                if(is_object($this->controller_object)) { 
     547                     
    539548                    $this->controller_object->controller = $this->controller; 
    540549                    $this->controller_object->action = $this->action; 
     
    552561                    // error_log('$GLOBALS[\'current_controller_path\']=' 
    553562                    //           .$GLOBALS['current_controller_path']); 
    554                 } 
    555  
    556                 # Which layout should we use? 
    557                 $layout_file = $this->determine_layout(); 
    558                 //error_log('layout_file="'.$layout_file.'"'); 
    559                  
    560                 # Check if there is any defined scaffolding to load 
    561                 if(isset($this->controller_object->scaffold)) { 
    562                     $scaffold = $this->controller_object->scaffold; 
    563                     if(file_exists(TRAX_LIB_ROOT."/scaffold_controller.php")) { 
    564                         include_once(TRAX_LIB_ROOT."/scaffold_controller.php"); 
    565                         $this->controller_object = new ScaffoldController($scaffold); 
    566                         $GLOBALS['current_controller_object'] =& $this->controller_object; 
    567                         $render_options['scaffold'] = true; 
    568                         if(!file_exists($layout_file)) { 
    569                             # the generic scaffold layout 
    570                             $layout_file = TRAX_LIB_ROOT . "/templates/scaffolds/layout.phtml"; 
     563 
     564                    # Which layout should we use? 
     565                    $layout_file = $this->controller_object->determine_layout(); 
     566                    //error_log('layout_file="'.$layout_file.'"'); 
     567                     
     568                    # Check if there is any defined scaffolding to load 
     569                    if(isset($this->controller_object->scaffold)) { 
     570                        $scaffold = $this->controller_object->scaffold; 
     571                        if(file_exists(TRAX_LIB_ROOT."/scaffold_controller.php")) { 
     572                            include_once(TRAX_LIB_ROOT."/scaffold_controller.php"); 
     573                            $this->controller_object = new ScaffoldController($scaffold); 
     574                            $GLOBALS['current_controller_object'] =& $this->controller_object; 
     575                            $render_options['scaffold'] = true; 
     576                            if(!file_exists($layout_file)) { 
     577                                # the generic scaffold layout 
     578                                $layout_file = TRAX_LIB_ROOT . "/templates/scaffolds/layout.phtml"; 
     579                            } 
    571580                        } 
    572581                    } 
     
    626635                    } 
    627636                    $this->controller_object->execute_after_filters(); 
    628                  
     637                     
     638                    $this->controller_object->action_called = true; 
     639                     
    629640                    # Find out if there was a redirect to some other page 
    630641                    if(isset($this->controller_object->redirect_to) 
     
    828839     */ 
    829840    function render($options = array(), $locals = array(), $return_as_string = false) { 
     841         
     842        if($this->render_performed && !$this->action_called) { 
     843            return true;     
     844        } 
     845         
    830846        if($return_as_string) { 
    831847            # start to buffer output 
     
    855871        }  
    856872         
     873        $this->render_performed = true; 
     874 
    857875        if($return_as_string) { 
    858876            $result = ob_get_contents(); 
     
    883901    function render_text($text, $options = array()) {        
    884902        if($options['layout']) { 
    885             $locals['content_for_layout'] = $text; 
    886             $layout = $this->determine_layout(false); 
    887             $this->render($layout, $locals);     
     903            $locals['content_for_layout'] = $text;          
     904            $layout = $this->determine_layout(); 
     905            $this->render_file($layout, false, $locals);   
    888906        } else { 
    889907            echo $text;     
     
    911929     */     
    912930    function render_action($action, $options = array()) { 
    913         if($this->action_render_performed) { 
     931        if($this->render_performed) { 
    914932            return true;     
    915933        } 
    916934        if($options['layout']) { 
    917             $this->controller_object->layout = $options['layout'];     
     935            $this->layout = $options['layout'];     
    918936        }  
    919937        if($options['scaffold']) { 
     
    923941        } 
    924942        #error_log(get_class($this)." - render_action() view_file: $this->view_file"); 
    925         if($this->render_file($this->view_file)) { 
    926             $this->action_render_performed = true; 
    927             return true;    
    928         }  
    929         return false; 
     943        return $this->render_file($this->view_file); 
    930944    } 
    931945     
     
    957971     */ 
    958972    function render_file($path, $use_full_path = false, $locals = array()) { 
     973        if($this->render_performed && !$this->action_called) { 
     974            return true;     
     975        }         
     976         
    959977        # Renders a template relative to app/views 
    960978        if($use_full_path) { 
    961979            $path = $this->views_path."/".$path.".".$this->views_file_extention; 
    962980        }  
     981 
    963982        //error_log("render_file() path:$path"); 
    964983        if(file_exists($path)) { 
     
    978997                unset($tmp_value); 
    979998            }         
    980             include($path);   
     999            include($path); 
     1000            $this->render_performed = true;   
    9811001            return true;       
    9821002        }      
     
    10541074                    $locals[$file."_counter"] = ${$file."_counter"}; 
    10551075                    unset($tmp_value);  
     1076                    $this->render_performed = false; 
    10561077                    $this->render_file($file_with_path, false, $locals);    
    10571078                    if($add_spacer && (${$file."_counter"} < count($options['collection']))) {  
     1079                        $this->render_performed = false; 
    10581080                        $this->render_file($spacer_file_with_file, false, $locals);       
    10591081                    }          
    1060                 }     
     1082                }  
     1083                $this->render_performed = true;    
    10611084            } else {               
    10621085                $this->render_file($file_with_path, false, $locals);         
    1063             }            
     1086            }           
    10641087        } 
    10651088    } 
     
    10761099    function determine_layout($full_path = true) { 
    10771100        # I guess you don't want any layout 
    1078         if($this->controller_object->layout == "null") { 
     1101        if($this->layout == "null") { 
    10791102            //error_log('controller->layout absent'); 
    10801103            return null; 
     
    10821105        # $layout will be the layout defined in the current controller 
    10831106        # or try to use the controller name for the layout 
    1084         $layout = (isset($this->controller_object->layout) 
    1085                    && $this->controller_object->layout != '') 
    1086             ? $this->controller_object->layout : $this->controller; 
     1107        $layout = (isset($this->layout) 
     1108                   && $this->layout != '') 
     1109            ? $this->layout : $this->controller; 
    10871110         
    10881111        # Check if a method has been defined to determine the layout at runtime 
    1089         if(method_exists($this->controller_object, $layout)) { 
    1090             $layout = $this->controller_object->$layout(); 
    1091         } 
    1092          
     1112        if(method_exists($this, $layout)) { 
     1113            $layout = $this->$layout(); 
     1114        } 
     1115 
    10931116        # Default settings 
    10941117        $layouts_base_path = TRAX_ROOT . $GLOBALS['TRAX_INCLUDES']['layouts']; 
     
    11031126                $path = substr($layout, 0, strripos($layout, "/")); 
    11041127                $layout = $layouts_base_path."/".$path."/".$file.".".$this->views_file_extention; 
    1105             } elseif($this->controller_object->layout != '') { 
     1128            } elseif($this->layout != '') { 
    11061129                # Is there a layout for the current controller 
    1107                 $layout = $layouts_base_path."/".$layout.".".$this->views_file_extention;                     
     1130                $layout = $layouts_base_path."/".$this->layout.".".$this->views_file_extention;                     
    11081131            } else { 
    11091132                # Is there a layout for the current controller