Changeset 312 for trunk/trax/vendor/trax/action_controller.php
- Timestamp:
- 04/25/09 12:36:11 (3 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/action_controller.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_controller.php
r311 r312 469 469 470 470 // ':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 } 472 475 } elseif(is_array($route_path) 473 476 && in_array(":controller",$route_path) … … 507 510 #print_r($this->url_path); 508 511 #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) { 511 514 #array_unshift($this->url_path, $extra_path); 512 }513 }515 #} 516 #} 514 517 #print_r($this->url_path); 515 518 … … 525 528 $this->views_path .= "/" . $this->controller; 526 529 $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}"); 529 533 } 530 534 } 531 535 532 if( file_exists($this->controller_file)) {536 if(is_file($this->controller_file)) { 533 537 $this->loaded = true; 534 538 return true; … … 688 692 $this->controller_object->index(); 689 693 } 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"); 692 700 } 693 701 … … 726 734 if(!$this->controller_object->render_action($action, 727 735 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"); 729 737 } 730 738 # Grab all the html from the view to put into the layout … … 785 793 * @uses $views_path 786 794 * @uses $url_path 787 * @todo <b>FIXME:</b> Creating a file or directory in788 * app/controllers with the same name as a controller, action or789 * other URL element will hijack the browser!790 795 */ 791 796 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); 801 820 } 802 821 } 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)); 804 824 $this->extra_path = $extra_path; 805 825 $extra_path = implode("/", $extra_path); … … 809 829 $this->views_path .= "/$extra_path"; 810 830 $this->layouts_path .= "/$extra_path"; 811 }812 if(isset($new_path)813 && is_array($new_path)) {814 $this->url_path = $new_path;815 831 } 816 832 }
