Changeset 73 for trunk/trax/vendor/trax/action_controller.php
- Timestamp:
- 12/05/05 00:20:32 (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
r72 r73 1 1 <? 2 # $Id : action_controller.php 55 2005-11-11 22:38:37Z john$2 # $Id$ 3 3 # 4 4 # Copyright (c) 2005 John Peterson … … 91 91 $browser_url = str_replace(TRAX_URL_PREFIX,"",$browser_url); 92 92 } 93 93 94 94 # strip leading slash 95 95 $browser_url = substr($browser_url,1); … … 181 181 $class = $this->controller_class; 182 182 $this->controller_object = new $class(); 183 183 184 184 $layout = $this->controller_object->layout; 185 185 # Call class method to set the layout dynamically at runtime 186 if(method_exists($this->controller_object, $layout)) { 187 $layout = $this->controller_object->$layout(); 188 } 189 186 if(method_exists($this->controller_object, $layout)) { 187 $layout = $this->controller_object->$layout(); 188 } 189 190 190 # Check if there is any defined scaffolding to load 191 if($this->controller_object->scaffold) { 192 $scaffold = $this->controller_object->scaffold; 193 if(file_exists(TRAX_ ROOT.$GLOBALS['TRAX_INCLUDES']['lib']."/scaffold_controller.php")) {194 include_once(TRAX_ ROOT.$GLOBALS['TRAX_INCLUDES']['lib']."/scaffold_controller.php");195 $this->controller_object = new ScaffoldController($scaffold, $this->controller, $this->action); 191 if($this->controller_object->scaffold) { 192 $scaffold = $this->controller_object->scaffold; 193 if(file_exists(TRAX_LIB_ROOT."/scaffold_controller.php")) { 194 include_once(TRAX_LIB_ROOT."/scaffold_controller.php"); 195 $this->controller_object = new ScaffoldController($scaffold, $this->controller, $this->action); 196 196 if($this->action) { 197 $this->view_file = TRAX_ ROOT.$GLOBALS['TRAX_INCLUDES']['lib'] . "/templates/scaffolds/".$this->action.".phtml";197 $this->view_file = TRAX_LIB_ROOT . "/templates/scaffolds/".$this->action.".phtml"; 198 198 } else { 199 $this->view_file = TRAX_ ROOT.$GLOBALS['TRAX_INCLUDES']['lib'] . "/templates/scaffolds/index.phtml";199 $this->view_file = TRAX_LIB_ROOT . "/templates/scaffolds/index.phtml"; 200 200 } 201 201 if($layout == "") { 202 202 # the generic scaffold layout 203 $this->layout_file = TRAX_ ROOT.$GLOBALS['TRAX_INCLUDES']['lib']. "/templates/scaffolds/layout.phtml";204 } 203 $this->layout_file = TRAX_LIB_ROOT . "/templates/scaffolds/layout.phtml"; 204 } 205 205 } 206 206 } 207 208 207 } 209 208 … … 257 256 } else { 258 257 $this->view_file = $this->views_path . "/" . "index" . "." . $this->views_file_extention; 259 } 258 } 260 259 } 261 260 262 261 if(file_exists($this->view_file)) { 263 262 # grab view html … … 265 264 } else { 266 265 $this->raise("No view file found $action ($this->view_file).", "Unknown view", "404"); 267 } 268 266 } 267 269 268 # Grab all the html from the view to put into the layout 270 269 $content_for_layout .= ob_get_contents(); 271 270 ob_end_clean(); 272 271 273 if(!$this->layout_file) { 272 if(!$this->layout_file) { 274 273 $this->layout_file = $this->layouts_path . "/" . $layout . "." . $this->views_file_extention; 275 } 276 274 } 275 277 276 if(file_exists($this->layout_file)) { 278 277 # render user defined layout … … 286 285 # No layout template so just echo out whatever is in $content_for_layout 287 286 echo $content_for_layout; 288 } 287 } 289 288 } 290 289 } else { … … 296 295 297 296 if(!$this->keep_flash) { 298 # Nuke the flash array 299 Session:: 300 unset($_SESSION['flash']); 297 # Nuke the flash 298 Session::unset_var('flash'); 301 299 } 302 300 … … 307 305 if(is_array($this->url_path)) { 308 306 foreach($this->url_path as $path) { 309 if(file_exists($this->controllers_path . "/$path")) {307 if(file_exists($this->controllers_path . "/$path")) { 310 308 $this->controllers_path .= "/$path"; 311 309 $this->helpers_path .= "/$path"; … … 332 330 $filter_function = $this->controller_object->before_filter; 333 331 $this->controller_object->$filter_function(); 334 } 332 } 335 333 } 336 334 } … … 339 337 if (is_array($filter_function_name)) { 340 338 if(count($this->before_filter) > 0) { 341 $this->before_filter = array_merge($this->before_filter, $filter_function_name); 339 $this->before_filter = array_merge($this->before_filter, $filter_function_name); 342 340 } else { 343 341 $this->before_filter = $filter_function_name; … … 346 344 $this->before_filter = array($this->before_filter, $filter_function_name); 347 345 } else { 348 $this->before_filter = $filter_function_name; 346 $this->before_filter = $filter_function_name; 349 347 } 350 348 } … … 361 359 $filter_function = $this->controller_object->after_filter; 362 360 $this->controller_object->$filter_function(); 363 } 361 } 364 362 } 365 363 } … … 368 366 if (is_array($filter_function_name)) { 369 367 if(count($this->after_filter) > 0) { 370 $this->after_filter = array_merge($this->after_filter, $filter_function_name); 368 $this->after_filter = array_merge($this->after_filter, $filter_function_name); 371 369 } else { 372 370 $this->after_filter = $filter_function_name; 373 } 371 } 374 372 } elseif($this->after_filter != "") { 375 373 $this->after_filter = array($this->after_filter, $filter_function_name); 376 374 } else { 377 $this->after_filter = $filter_function_name; 375 $this->after_filter = $filter_function_name; 378 376 } 379 377 } … … 405 403 } 406 404 407 function raise($error_message, $error_heading, $error_code = "404") { 408 throw new ActionControllerError("Error Message: ".$error_message, $error_heading, $error_code); 405 function raise($error_message, $error_heading, $error_code = "404") { 406 throw new ActionControllerError("Error Message: ".$error_message, $error_heading, $error_code); 409 407 } 410 408 … … 414 412 $error_message = $exception->error_message; 415 413 $trace = $exception->getTraceAsString(); 416 header("HTTP/1.0 {$error_code} {$error_heading}"); 414 header("HTTP/1.0 {$error_code} {$error_heading}"); 417 415 # check for user's layout for errors 418 416 if(DEBUG && file_exists(TRAX_ROOT.$GLOBALS['TRAX_INCLUDES']['layouts']."/error.phtml")) {
