Show
Ignore:
Timestamp:
04/20/06 10:20:30 (6 years ago)
Author:
haas
Message:

DateHelper? docs and tests

Files:
1 modified

Legend:

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

    r197 r198  
    5050     *  Name of the controller (without the _controller.php) 
    5151     * 
    52      *  Set by {@link recognize_route()} 
     52     *  Set by {@link recognize_route()} by parsing the URL and the 
     53     *  routes in {@link routes.php}.  The value of this string is set 
     54     *  before any attempt is made to find the file containing the 
     55     *  controller. 
    5356     *  @var string 
    5457     */ 
     
    456459            //  matches the URL, null if no match found 
    457460            if(is_array($route)) { 
     461 
     462                //  Matching route found.  Try to get 
     463                //  controller and action from route and URL 
    458464                $this->set_paths(); 
    459465                $route_path = explode("/",$route['path']); 
    460466                $route_params = $route['params']; 
    461467 
    462                 if(@array_key_exists(":controller",$route_params)) { 
     468                //  Find the controller from the route and URL 
     469                if(is_array($route_params) 
     470                   && array_key_exists(":controller",$route_params)) { 
     471 
     472                    //  ':controller' in route params overrides URL 
    463473                    $this->controller = $route_params[":controller"]; 
    464                 } elseif(@in_array(":controller",$route_path)) { 
    465                     $this->controller = strtolower($this->url_path[@array_search(":controller", $route_path)]); 
     474                } elseif(is_array($route_path) 
     475                         && in_array(":controller",$route_path) 
     476                         && (count($this->url_path)>0)) { 
     477 
     478                    //  Set controller from URL if that field exists 
     479                    $this->controller = strtolower($this->url_path[array_search(":controller", $route_path)]); 
    466480                } 
    467481                //error_log('controller='.$this->controller); 
    468                 if(@array_key_exists(":action",$route_params)) { 
     482 
     483                //  Find the actionfrom the route and URL 
     484                if(is_array($route_params) 
     485                   && array_key_exists(":action",$route_params)) { 
     486 
     487                    //  ':action' in route params overrides URL 
    469488                    $this->action = $route_params[':action']; 
    470                 } elseif(@in_array(":action",$route_path) 
    471                    && array_key_exists(@array_search(":action", $route_path), 
    472                                        $this->url_path)) { 
     489                } elseif(is_array($route_path) 
     490                         && in_array(":action",$route_path) 
     491                         && array_key_exists(@array_search(":action", 
     492                                                           $route_path), 
     493                                             $this->url_path)) { 
     494 
     495                    //  Get action from URL if that field exists 
    473496                    $this->action = strtolower($this->url_path[@array_search(":action", $route_path)]); 
    474497                } 
     
    627650                # Suppress output 
    628651                ob_start(); 
     652                //error_log('started capturing HTML'); 
    629653                 
    630654                # Call the controller method based on the URL 
     
    632656                    
    633657                    if(method_exists($this->controller_object, $this->action)) { 
    634                         error_log('controller has method "'.$this->action.'"'); 
     658                        //error_log('method '.$this->action.' exists, calling it'); 
    635659                        $action = $this->action; 
    636660                        $this->controller_object->$action(); 
    637661                    } elseif(file_exists($this->views_path . "/" . $this->action . "." . $this->views_file_extention)) { 
    638                         error_log('views file "'.$this->action.'"'); 
     662                        //error_log('views file "'.$this->action.'"'); 
    639663                        $action = $this->action; 
    640664                    } elseif(method_exists($this->controller_object, "index")) { 
    641                         error_log('calling index()'); 
     665                        //error_log('calling index()'); 
    642666                        $action = "index"; 
    643667                        $this->controller_object->index(); 
    644668                    } else { 
    645                         error_log('no action'); 
     669                        //error_log('no action'); 
    646670                        $this->raise("No action responded to ".$this->action, "Unknown action", "404"); 
    647671                    } 
     
    671695                     
    672696                    # Render the action / view                       
    673                     if(!$this->controller_object->render_action($action, $render_options)) { 
     697                    if(!$this->controller_object->render_action($action, 
     698                          isset($render_options) ? $render_options : null )) { 
    674699                        $this->raise("No view file found $action ($this->view_file).", "Unknown view", "404"); 
    675700                    } 
    676  
    677701                    # Grab all the html from the view to put into the layout 
    678702                    $content_for_layout = ob_get_contents(); 
    679703                    ob_end_clean(); 
    680          
     704                    //error_log("captured ".strlen($content_for_layout)." bytes\n"); 
    681705                    if(isset($this->controller_object->render_layout) 
    682706                       && ($this->controller_object->render_layout !== false) 
     
    768792                if(method_exists($this, $filter_function)) { 
    769793                    if(false === $this->$filter_function()) { 
    770                         error_log("execute_before_filters(): returning false"); 
     794                        //error_log("execute_before_filters(): returning false"); 
    771795                        $return = false;     
    772796                    } 
     
    786810     */ 
    787811    function add_before_filter($filter_function_name) { 
    788         error_log("adding before filter: $filter_function_name"); 
     812        //error_log("adding before filter: $filter_function_name"); 
    789813        if(is_string($filter_function_name) && !empty($filter_function_name)) { 
    790814            if(!in_array($filter_function_name, $this->before_filters)) { 
     
    11161140     */ 
    11171141    function determine_layout($full_path = true) { 
    1118         # I guess you don't want any layout 
    1119         if($this->layout == "null") { 
     1142 
     1143        //  If the controller defines $layout and sets it 
     1144        //  to NULL, that indicates it doesn't want a layout 
     1145        if(isset($this->layout) && is_null($this->layout)) { 
    11201146            //error_log('controller->layout absent'); 
    11211147            return null; 
     
    11441170                $path = substr($layout, 0, strripos($layout, "/")); 
    11451171                $layout = $layouts_base_path."/".$path."/".$file.".".$this->views_file_extention; 
    1146             } elseif($this->layout != '') { 
     1172            } elseif( isset($this->layout) && ($this->layout != '') ) { 
    11471173                # Is there a layout for the current controller 
    11481174                $layout = $layouts_base_path."/".$this->layout.".".$this->views_file_extention;