Changeset 312 for trunk/trax/vendor

Show
Ignore:
Timestamp:
04/25/09 12:36:11 (3 years ago)
Author:
john
Message:

fixed namespaced controllers

Files:
1 modified

Legend:

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

    r311 r312  
    469469 
    470470                    //  ':controller' in route params overrides URL 
    471                     $this->controller = $route_params[":controller"]; 
     471                    $this->controller = $route_params[":controller"];   
     472                    if(stristr($route_params[":controller"], "/")) { 
     473                         
     474                    } 
    472475                } elseif(is_array($route_path) 
    473476                         && in_array(":controller",$route_path) 
     
    507510                    #print_r($this->url_path); 
    508511                    #print_r($route_path); 
    509                     if(count($this->extra_path)) { 
    510                         foreach(array_reverse($this->extra_path) as $extra_path) { 
     512                    #if(count($this->extra_path)) { 
     513                        #foreach(array_reverse($this->extra_path) as $extra_path) { 
    511514                            #array_unshift($this->url_path, $extra_path); 
    512                         } 
    513                     } 
     515                        #} 
     516                    #} 
    514517                    #print_r($this->url_path); 
    515518 
     
    525528                $this->views_path .= "/" . $this->controller; 
    526529                $this->controller_file = $this->controllers_path . "/" .  $this->controller . "_controller.php"; 
    527                 $this->controller_class = Inflector::camelize($this->controller) . "Controller"; 
    528                 $this->helper_file = $this->helpers_path . "/" .  $this->controller . "_helper.php"; 
     530                $this->controller_class = Inflector::camelize(Inflector::demodulize($this->controller)) . "Controller"; 
     531                $this->helper_file = $this->helpers_path . "/" .  $this->controller . "_helper.php";   
     532                #error_log("controller:{$this->controller} - controller_file:{$this->controller_file} - controller_class:{$this->controller_class} - views_path:{$this->views_path}"); 
    529533            } 
    530534        } 
    531535 
    532         if(file_exists($this->controller_file)) { 
     536        if(is_file($this->controller_file)) { 
    533537            $this->loaded = true; 
    534538            return true; 
     
    688692                        $this->controller_object->index(); 
    689693                    } else { 
    690                         //error_log('no action'); 
    691                         $this->raise("No action responded to ".$this->action, "Unknown action", "404"); 
     694                        //error_log('no action');    
     695                        $methods_size = count($action_methods);        
     696                        if($methods_size > 1) { 
     697                            $last_method = ($methods_size > 2 ? "," : '')." and ".array_pop($action_methods); 
     698                        } 
     699                        $this->raise("No action responded to ".$this->action.". Actions:".implode(", ",$action_methods).$last_method, "Unknown action", "404"); 
    692700                    } 
    693701                     
     
    726734                    if(!$this->controller_object->render_action($action, 
    727735                          isset($render_options) ? $render_options : null )) { 
    728                         $this->raise("No view file found $action ($this->view_file).", "Unknown view", "404"); 
     736                        $this->raise("No view file found $action ($this->view_file).", "Unknown view", "404");  
    729737                    } 
    730738                    # Grab all the html from the view to put into the layout 
     
    785793     *  @uses $views_path 
    786794     *  @uses $url_path 
    787      *  @todo <b>FIXME:</b> Creating a file or directory in 
    788      *        app/controllers with the same name as a controller, action or 
    789      *        other URL element will hijack the browser! 
    790795     */ 
    791796    function set_paths() { 
    792         if(is_array($this->url_path)) { 
    793             $test_path = null; 
    794             foreach($this->url_path as $path) { 
    795                 $test_path = (is_null($test_path) ? $path : "$test_path/$path"); 
    796                 if(is_dir($this->controllers_path . "/$test_path")) { 
    797                     $extra_path[] = $path; 
    798                 } else { 
    799                     $test_path = null; 
    800                     $new_path[] = $path; 
     797        if(is_array($this->url_path)) {                      
     798            $path_size = count($this->url_path) - 1; 
     799            $test_path = $this->controllers_path;   
     800            $url_path = $this->url_path;           
     801            foreach($url_path as $position => $path) {          
     802                $test_path .= "/$path";   
     803                $test_file = $test_path."_controller.php";                  
     804                if(is_file($test_file)) {       
     805                    $next = isset($url_path[$position+1]) ?  
     806                        $test_path ."/".$url_path[$position+1] : 
     807                        null;      
     808                    if(!is_null($next)) { 
     809                        if(is_file($next."_controller.php") || is_dir($next)) { 
     810                            $extra_path[] = $path;    
     811                            array_shift($this->url_path);                             
     812                        } 
     813                    } else { 
     814                        #error_log("found controller path:$path");                     
     815                        break;                         
     816                    }               
     817                } elseif(is_dir($test_path)) {      
     818                    $extra_path[] = $path;    
     819                    array_shift($this->url_path); 
    801820                } 
    802821            } 
    803             if(isset($extra_path) && is_array($extra_path)) { 
     822            if(isset($extra_path) && is_array($extra_path)) {   
     823                #error_log("extra_path:".print_r($extra_path, true)); 
    804824                $this->extra_path = $extra_path; 
    805825                $extra_path = implode("/", $extra_path); 
     
    809829                $this->views_path .= "/$extra_path"; 
    810830                $this->layouts_path .= "/$extra_path"; 
    811             } 
    812             if(isset($new_path) 
    813                && is_array($new_path)) { 
    814                 $this->url_path = $new_path; 
    815831            } 
    816832        }