Changeset 176 for trunk/trax/vendor/trax/action_controller.php
- Timestamp:
- 03/14/06 03:21:43 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/action_controller.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_controller.php
r175 r176 203 203 */ 204 204 private $action_render_performed = false; 205 206 /** 207 * @todo Document this attribute 208 */ 209 private $action_called = false; 205 210 206 211 /** … … 532 537 # If controller is loaded then start processing 533 538 if($this->loaded) { 539 534 540 include_once($this->controller_file); 535 541 if(class_exists($this->controller_class, false)) { 542 536 543 $class = $this->controller_class; 537 544 $this->controller_object = new $class(); 545 538 546 if(is_object($this->controller_object)) { 547 539 548 $this->controller_object->controller = $this->controller; 540 549 $this->controller_object->action = $this->action; … … 552 561 // error_log('$GLOBALS[\'current_controller_path\']=' 553 562 // .$GLOBALS['current_controller_path']); 554 } 555 556 # Which layout should we use?557 $layout_file = $this->determine_layout();558 //error_log('layout_file="'.$layout_file.'"');559 560 # Check if there is any defined scaffolding to load561 if(isset($this->controller_object->scaffold)) {562 $scaffold = $this->controller_object->scaffold;563 if(file_exists(TRAX_LIB_ROOT."/scaffold_controller.php")) {564 include_once(TRAX_LIB_ROOT."/scaffold_controller.php");565 $this->controller_object = new ScaffoldController($scaffold);566 $GLOBALS['current_controller_object'] =& $this->controller_object;567 $render_options['scaffold'] = true;568 if(!file_exists($layout_file)) {569 # the generic scaffold layout570 $layout_file = TRAX_LIB_ROOT . "/templates/scaffolds/layout.phtml";563 564 # Which layout should we use? 565 $layout_file = $this->controller_object->determine_layout(); 566 //error_log('layout_file="'.$layout_file.'"'); 567 568 # Check if there is any defined scaffolding to load 569 if(isset($this->controller_object->scaffold)) { 570 $scaffold = $this->controller_object->scaffold; 571 if(file_exists(TRAX_LIB_ROOT."/scaffold_controller.php")) { 572 include_once(TRAX_LIB_ROOT."/scaffold_controller.php"); 573 $this->controller_object = new ScaffoldController($scaffold); 574 $GLOBALS['current_controller_object'] =& $this->controller_object; 575 $render_options['scaffold'] = true; 576 if(!file_exists($layout_file)) { 577 # the generic scaffold layout 578 $layout_file = TRAX_LIB_ROOT . "/templates/scaffolds/layout.phtml"; 579 } 571 580 } 572 581 } … … 626 635 } 627 636 $this->controller_object->execute_after_filters(); 628 637 638 $this->controller_object->action_called = true; 639 629 640 # Find out if there was a redirect to some other page 630 641 if(isset($this->controller_object->redirect_to) … … 828 839 */ 829 840 function render($options = array(), $locals = array(), $return_as_string = false) { 841 842 if($this->render_performed && !$this->action_called) { 843 return true; 844 } 845 830 846 if($return_as_string) { 831 847 # start to buffer output … … 855 871 } 856 872 873 $this->render_performed = true; 874 857 875 if($return_as_string) { 858 876 $result = ob_get_contents(); … … 883 901 function render_text($text, $options = array()) { 884 902 if($options['layout']) { 885 $locals['content_for_layout'] = $text; 886 $layout = $this->determine_layout( false);887 $this->render ($layout, $locals);903 $locals['content_for_layout'] = $text; 904 $layout = $this->determine_layout(); 905 $this->render_file($layout, false, $locals); 888 906 } else { 889 907 echo $text; … … 911 929 */ 912 930 function render_action($action, $options = array()) { 913 if($this-> action_render_performed) {931 if($this->render_performed) { 914 932 return true; 915 933 } 916 934 if($options['layout']) { 917 $this-> controller_object->layout = $options['layout'];935 $this->layout = $options['layout']; 918 936 } 919 937 if($options['scaffold']) { … … 923 941 } 924 942 #error_log(get_class($this)." - render_action() view_file: $this->view_file"); 925 if($this->render_file($this->view_file)) { 926 $this->action_render_performed = true; 927 return true; 928 } 929 return false; 943 return $this->render_file($this->view_file); 930 944 } 931 945 … … 957 971 */ 958 972 function render_file($path, $use_full_path = false, $locals = array()) { 973 if($this->render_performed && !$this->action_called) { 974 return true; 975 } 976 959 977 # Renders a template relative to app/views 960 978 if($use_full_path) { 961 979 $path = $this->views_path."/".$path.".".$this->views_file_extention; 962 980 } 981 963 982 //error_log("render_file() path:$path"); 964 983 if(file_exists($path)) { … … 978 997 unset($tmp_value); 979 998 } 980 include($path); 999 include($path); 1000 $this->render_performed = true; 981 1001 return true; 982 1002 } … … 1054 1074 $locals[$file."_counter"] = ${$file."_counter"}; 1055 1075 unset($tmp_value); 1076 $this->render_performed = false; 1056 1077 $this->render_file($file_with_path, false, $locals); 1057 1078 if($add_spacer && (${$file."_counter"} < count($options['collection']))) { 1079 $this->render_performed = false; 1058 1080 $this->render_file($spacer_file_with_file, false, $locals); 1059 1081 } 1060 } 1082 } 1083 $this->render_performed = true; 1061 1084 } else { 1062 1085 $this->render_file($file_with_path, false, $locals); 1063 } 1086 } 1064 1087 } 1065 1088 } … … 1076 1099 function determine_layout($full_path = true) { 1077 1100 # I guess you don't want any layout 1078 if($this-> controller_object->layout == "null") {1101 if($this->layout == "null") { 1079 1102 //error_log('controller->layout absent'); 1080 1103 return null; … … 1082 1105 # $layout will be the layout defined in the current controller 1083 1106 # or try to use the controller name for the layout 1084 $layout = (isset($this-> controller_object->layout)1085 && $this-> controller_object->layout != '')1086 ? $this-> controller_object->layout : $this->controller;1107 $layout = (isset($this->layout) 1108 && $this->layout != '') 1109 ? $this->layout : $this->controller; 1087 1110 1088 1111 # Check if a method has been defined to determine the layout at runtime 1089 if(method_exists($this ->controller_object, $layout)) {1090 $layout = $this-> controller_object->$layout();1091 } 1092 1112 if(method_exists($this, $layout)) { 1113 $layout = $this->$layout(); 1114 } 1115 1093 1116 # Default settings 1094 1117 $layouts_base_path = TRAX_ROOT . $GLOBALS['TRAX_INCLUDES']['layouts']; … … 1103 1126 $path = substr($layout, 0, strripos($layout, "/")); 1104 1127 $layout = $layouts_base_path."/".$path."/".$file.".".$this->views_file_extention; 1105 } elseif($this-> controller_object->layout != '') {1128 } elseif($this->layout != '') { 1106 1129 # Is there a layout for the current controller 1107 $layout = $layouts_base_path."/".$ layout.".".$this->views_file_extention;1130 $layout = $layouts_base_path."/".$this->layout.".".$this->views_file_extention; 1108 1131 } else { 1109 1132 # Is there a layout for the current controller
