Changeset 198 for trunk/trax/vendor/trax/action_controller.php
- Timestamp:
- 04/20/06 10:20:30 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/action_controller.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_controller.php
r197 r198 50 50 * Name of the controller (without the _controller.php) 51 51 * 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. 53 56 * @var string 54 57 */ … … 456 459 // matches the URL, null if no match found 457 460 if(is_array($route)) { 461 462 // Matching route found. Try to get 463 // controller and action from route and URL 458 464 $this->set_paths(); 459 465 $route_path = explode("/",$route['path']); 460 466 $route_params = $route['params']; 461 467 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 463 473 $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)]); 466 480 } 467 481 //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 469 488 $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 473 496 $this->action = strtolower($this->url_path[@array_search(":action", $route_path)]); 474 497 } … … 627 650 # Suppress output 628 651 ob_start(); 652 //error_log('started capturing HTML'); 629 653 630 654 # Call the controller method based on the URL … … 632 656 633 657 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'); 635 659 $action = $this->action; 636 660 $this->controller_object->$action(); 637 661 } 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.'"'); 639 663 $action = $this->action; 640 664 } elseif(method_exists($this->controller_object, "index")) { 641 error_log('calling index()');665 //error_log('calling index()'); 642 666 $action = "index"; 643 667 $this->controller_object->index(); 644 668 } else { 645 error_log('no action');669 //error_log('no action'); 646 670 $this->raise("No action responded to ".$this->action, "Unknown action", "404"); 647 671 } … … 671 695 672 696 # 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 )) { 674 699 $this->raise("No view file found $action ($this->view_file).", "Unknown view", "404"); 675 700 } 676 677 701 # Grab all the html from the view to put into the layout 678 702 $content_for_layout = ob_get_contents(); 679 703 ob_end_clean(); 680 704 //error_log("captured ".strlen($content_for_layout)." bytes\n"); 681 705 if(isset($this->controller_object->render_layout) 682 706 && ($this->controller_object->render_layout !== false) … … 768 792 if(method_exists($this, $filter_function)) { 769 793 if(false === $this->$filter_function()) { 770 error_log("execute_before_filters(): returning false");794 //error_log("execute_before_filters(): returning false"); 771 795 $return = false; 772 796 } … … 786 810 */ 787 811 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"); 789 813 if(is_string($filter_function_name) && !empty($filter_function_name)) { 790 814 if(!in_array($filter_function_name, $this->before_filters)) { … … 1116 1140 */ 1117 1141 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)) { 1120 1146 //error_log('controller->layout absent'); 1121 1147 return null; … … 1144 1170 $path = substr($layout, 0, strripos($layout, "/")); 1145 1171 $layout = $layouts_base_path."/".$path."/".$file.".".$this->views_file_extention; 1146 } elseif( $this->layout != '') {1172 } elseif( isset($this->layout) && ($this->layout != '') ) { 1147 1173 # Is there a layout for the current controller 1148 1174 $layout = $layouts_base_path."/".$this->layout.".".$this->views_file_extention;
