Show
Ignore:
Timestamp:
03/09/06 12:50:58 (6 years ago)
Author:
haas
Message:

improve various test, documents

Files:
1 modified

Legend:

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

    r164 r165  
    207207 
    208208    /** 
     209     *  Path to add to other filesystem paths 
     210     * 
     211     *  Set by {@link recognize_route()} 
     212     *  @var string 
     213     */ 
     214    private $added_path = ''; 
     215      
     216    /** 
    209217     *  Filesystem path to ../app/controllers/ directory 
    210218     * 
     
    263271     * 
    264272     *  Set by {@link recognize_route()} 
     273     *  @see $controller_file 
    265274     *  @var string 
    266275     */ 
     
    322331 
    323332    /** 
     333     *  Filesystem path to the PHP program file for this controller 
     334     * 
     335     *  Set by {@link recognize_route()} 
     336     *  @see $application_controller_file 
     337     *  @var string 
     338     */ 
     339    public $controller_file; 
     340 
     341    /** 
    324342     *  @todo Document this attribute 
    325343     */ 
    326     public $controller_file; 
     344    public $view_file; 
     345 
     346    /** 
     347     *  Filesystem path to the ../app/views/ directory 
     348     * 
     349     *  Set by {@link recognize_route()} 
     350     *  @var string 
     351     */ 
     352    public $views_path; 
     353 
     354    /** 
     355     *  Class name of the controller 
     356     * 
     357     *  Set by {@link recognize_route()}. 
     358     *  Derived from contents of {@link $controller}. 
     359     *  @var string 
     360     */ 
     361    public $controller_class; 
     362 
     363    /** 
     364     *  Instance of the controller class 
     365     * 
     366     *  Set by {@link process_route()} 
     367     *  @var object 
     368     */ 
     369    public $controller_object; 
    327370 
    328371    /** 
    329372     *  @todo Document this attribute 
    330373     */ 
    331     public $view_file; 
    332  
    333     /** 
    334      *  Filesystem path to the ../app/views/ directory 
    335      * 
    336      *  Set by {@link recognize_route()} 
    337      *  @var string 
    338      */ 
    339     public $views_path; 
     374    public $asset_host = null; 
    340375 
    341376    /** 
    342377     *  @todo Document this attribute 
    343378     */ 
    344     public $controller_class; 
    345  
    346     /** 
    347      *  @todo Document this attribute 
    348      */ 
    349     public $controller_object; 
    350  
    351     /** 
    352      *  @todo Document this attribute 
    353      */ 
    354     public $asset_host = null; 
    355  
    356     /** 
    357      *  @todo Document this attribute 
    358      */ 
    359379    public $views_file_extention = TRAX_VIEWS_EXTENTION; 
     380 
     381    /** 
     382     *  Whether to keep flash message after displaying it 
     383     *  @var boolean 
     384     */ 
     385    public $keep_flash = false; 
    360386 
    361387    /** 
     
    473499        # current url 
    474500        $browser_url = $_SERVER['REDIRECT_URL']; 
    475  
    476501        # strip off url prefix, if any 
    477502        if(!is_null(TRAX_URL_PREFIX)) { 
     
    516541                if(@array_key_exists(":action",$route_params)) { 
    517542                    $this->action = $route_params[':action']; 
    518                 } elseif(@in_array(":action",$route_path)) { 
     543                } elseif(@in_array(":action",$route_path) 
     544                   && array_key_exists(@array_search(":action", $route_path), 
     545                                       $this->url_path)) { 
    519546                    $this->action = strtolower($this->url_path[@array_search(":action", $route_path)]); 
    520547                } 
    521548 
    522                 //  FIXME: get a warning if ':id' not in $url_path 
    523                 if(@in_array(":id",$route_path)) { 
     549                if(@in_array(":id",$route_path) 
     550                   && array_key_exists(@array_search(":id", $route_path), 
     551                                       $this->url_path)) { 
    524552                    $this->id = strtolower($this->url_path[@array_search(":id", $route_path)]); 
    525553                    if($this->id != "") { 
     
    563591     *  @uses raise() 
    564592     *  @uses ScaffoldController 
     593     *  @uses Session::unset() 
    565594     *  @uses $view_file 
    566595     *  @uses $views_file_extention 
     
    579608        } 
    580609 
    581         # Surpress output 
     610        # Suppress output 
    582611        ob_start(); 
    583612 
     
    587616        } 
    588617 
     618        error_log('process_route() controller="'.$this->controller 
     619                  .'"  action="'.$this->action.'"'); 
    589620        # Include the controller file and execute action 
    590621        // FIXME: redundant, recognize_route() already test for file exists 
     
    597628                    $this->controller_object->controller = $this->controller; 
    598629                    $this->controller_object->action = $this->action; 
    599                     //  FIXME: $added_path doesn't exist at this point 
    600630                    $this->controller_object->controller_path = "$this->added_path/$this->controller"; 
    601631                    $GLOBALS['current_controller_path'] = "$this->added_path/$this->controller"; 
     
    603633                    $GLOBALS['current_action_name'] = $this->action; 
    604634                    $GLOBALS['current_controller_object'] =& $this->controller_object; 
     635                    error_log('$GLOBALS[\'current_action_name\']=' 
     636                              .$GLOBALS['current_action_name']); 
     637                    error_log('$GLOBALS[\'current_controller_name\']=' 
     638                              .$GLOBALS['current_controller_name']); 
     639                    error_log('$GLOBALS[\'current_controller_path\']=' 
     640                              .$GLOBALS['current_controller_path']); 
    605641                } 
    606642 
    607643                # Which layout should we use? 
    608644                $layout_file = $this->determine_layout(); 
    609  
     645                error_log('layout_file="'.$layout_file.'"'); 
    610646                # Check if there is any defined scaffolding to load 
    611                 if($this->controller_object->scaffold) { 
     647                if(isset($this->controller_object->scaffold)) { 
    612648                    $scaffold = $this->controller_object->scaffold; 
    613649                    if(file_exists(TRAX_LIB_ROOT."/scaffold_controller.php")) { 
     
    659695                $this->execute_before_filters(); 
    660696                if(method_exists($this->controller_object, $this->action)) { 
     697                    error_log('controller has method "'.$this->action.'"'); 
    661698                    $action = $this->action; 
    662699                    $this->controller_object->$action(); 
    663700                } elseif(file_exists($this->views_path . "/" . $this->action . "." . $this->views_file_extention)) { 
     701                    error_log('views file "'.$this->action.'"'); 
    664702                    $action = $this->action; 
    665703                } elseif(method_exists($this->controller_object, "index")) { 
     704                    error_log('calling index()'); 
    666705                    $this->controller_object->index(); 
    667706                } else { 
     707                    error_log('no action'); 
    668708                    $this->raise("No action responded to ".$this->action, "Unknown action", "404"); 
    669709                } 
     
    671711 
    672712                # Find out if there was a redirect to some other page 
    673                 if($this->controller_object->redirect_to) { 
     713                if(isset($this->controller_object->redirect_to) 
     714                    && $this->controller_object->redirect_to != '') { 
    674715                    $this->redirect_to($this->controller_object->redirect_to); 
    675716                } else { 
     
    678719                } 
    679720 
    680                 if($this->controller_object->render_text != "") { 
     721                if(isset($this->controller_object->render_text) 
     722                   && $this->controller_object->render_text != "") { 
    681723                    echo $this->controller_object->render_text; 
    682724                } else { 
    683725                    # If this isn't a scaffolding then get the view file to include 
    684                     if(!$scaffold) {  
     726                    if(!isset($scaffold)) {  
    685727                        # Normal processing of the view 
    686                         if($this->controller_object->render_action) { 
     728                        if(isset($this->controller_object->render_action) 
     729                           && $this->controller_object->render_action != '' ) { 
    687730                            $this->view_file = $this->views_path . "/" . $this->controller_object->render_action . "." . $this->views_file_extention; 
    688                         } elseif($action) { 
     731                        } elseif(isset($action) 
     732                                 && $action != '') { 
    689733                            $this->view_file = $this->views_path . "/" . $action . "." . $this->views_file_extention; 
    690734                        } else { 
     
    701745 
    702746                    # Grab all the html from the view to put into the layout 
    703                     $content_for_layout .= ob_get_contents(); 
     747                    $content_for_layout = ob_get_contents(); 
    704748                    ob_end_clean(); 
    705749 
     
    755799                $this->layouts_path .= "/$extra_path"; 
    756800            } 
    757             if(is_array($new_path)) { 
     801            if(isset($new_path) 
     802               && is_array($new_path)) { 
    758803                $this->url_path = $new_path; 
    759804            } 
     
    933978    function determine_layout() { 
    934979        # I guess you don't want any layout 
    935         // FIXME: Do we really want to test for null here? 
    936         // It might make more sense to test isset(...layout) 
    937         if($this->controller_object->layout == "null") { 
     980        if(!isset($this->controller_object->layout) 
     981           || $this->controller_object->layout == "null") { 
    938982            return null; 
    939983        } 
    940984        # $layout will be the layout defined in the current controller 
    941985        # or try to use the controller name for the layout 
    942         $layout = $this->controller_object->layout ? $this->controller_object->layout : $this->controller; 
     986        $layout = (isset($this->controller_object->layout) 
     987                   && $this->controller_object->layout != '') 
     988            ? $this->controller_object->layout : $this->controller; 
    943989        # Check if a method has been defined to determine the layout at runtime 
    944990        if(method_exists($this->controller_object, $layout)) { 
     
    9631009        //  FIXME: this file isn't in the distribution so 
    9641010        //  this reference will fail 
    965         if(!$layout_file) { 
     1011        if(!isset($layout_file)) { 
    9661012            $layout_file = $this->default_layout_file; 
    9671013        }