Changeset 165 for trunk/trax/vendor/trax/action_controller.php
- Timestamp:
- 03/09/06 12:50:58 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/action_controller.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_controller.php
r164 r165 207 207 208 208 /** 209 * Path to add to other filesystem paths 210 * 211 * Set by {@link recognize_route()} 212 * @var string 213 */ 214 private $added_path = ''; 215 216 /** 209 217 * Filesystem path to ../app/controllers/ directory 210 218 * … … 263 271 * 264 272 * Set by {@link recognize_route()} 273 * @see $controller_file 265 274 * @var string 266 275 */ … … 322 331 323 332 /** 333 * Filesystem path to the PHP program file for this controller 334 * 335 * Set by {@link recognize_route()} 336 * @see $application_controller_file 337 * @var string 338 */ 339 public $controller_file; 340 341 /** 324 342 * @todo Document this attribute 325 343 */ 326 public $controller_file; 344 public $view_file; 345 346 /** 347 * Filesystem path to the ../app/views/ directory 348 * 349 * Set by {@link recognize_route()} 350 * @var string 351 */ 352 public $views_path; 353 354 /** 355 * Class name of the controller 356 * 357 * Set by {@link recognize_route()}. 358 * Derived from contents of {@link $controller}. 359 * @var string 360 */ 361 public $controller_class; 362 363 /** 364 * Instance of the controller class 365 * 366 * Set by {@link process_route()} 367 * @var object 368 */ 369 public $controller_object; 327 370 328 371 /** 329 372 * @todo Document this attribute 330 373 */ 331 public $view_file; 332 333 /** 334 * Filesystem path to the ../app/views/ directory 335 * 336 * Set by {@link recognize_route()} 337 * @var string 338 */ 339 public $views_path; 374 public $asset_host = null; 340 375 341 376 /** 342 377 * @todo Document this attribute 343 378 */ 344 public $controller_class;345 346 /**347 * @todo Document this attribute348 */349 public $controller_object;350 351 /**352 * @todo Document this attribute353 */354 public $asset_host = null;355 356 /**357 * @todo Document this attribute358 */359 379 public $views_file_extention = TRAX_VIEWS_EXTENTION; 380 381 /** 382 * Whether to keep flash message after displaying it 383 * @var boolean 384 */ 385 public $keep_flash = false; 360 386 361 387 /** … … 473 499 # current url 474 500 $browser_url = $_SERVER['REDIRECT_URL']; 475 476 501 # strip off url prefix, if any 477 502 if(!is_null(TRAX_URL_PREFIX)) { … … 516 541 if(@array_key_exists(":action",$route_params)) { 517 542 $this->action = $route_params[':action']; 518 } elseif(@in_array(":action",$route_path)) { 543 } elseif(@in_array(":action",$route_path) 544 && array_key_exists(@array_search(":action", $route_path), 545 $this->url_path)) { 519 546 $this->action = strtolower($this->url_path[@array_search(":action", $route_path)]); 520 547 } 521 548 522 // FIXME: get a warning if ':id' not in $url_path 523 if(@in_array(":id",$route_path)) { 549 if(@in_array(":id",$route_path) 550 && array_key_exists(@array_search(":id", $route_path), 551 $this->url_path)) { 524 552 $this->id = strtolower($this->url_path[@array_search(":id", $route_path)]); 525 553 if($this->id != "") { … … 563 591 * @uses raise() 564 592 * @uses ScaffoldController 593 * @uses Session::unset() 565 594 * @uses $view_file 566 595 * @uses $views_file_extention … … 579 608 } 580 609 581 # Su rpress output610 # Suppress output 582 611 ob_start(); 583 612 … … 587 616 } 588 617 618 error_log('process_route() controller="'.$this->controller 619 .'" action="'.$this->action.'"'); 589 620 # Include the controller file and execute action 590 621 // FIXME: redundant, recognize_route() already test for file exists … … 597 628 $this->controller_object->controller = $this->controller; 598 629 $this->controller_object->action = $this->action; 599 // FIXME: $added_path doesn't exist at this point600 630 $this->controller_object->controller_path = "$this->added_path/$this->controller"; 601 631 $GLOBALS['current_controller_path'] = "$this->added_path/$this->controller"; … … 603 633 $GLOBALS['current_action_name'] = $this->action; 604 634 $GLOBALS['current_controller_object'] =& $this->controller_object; 635 error_log('$GLOBALS[\'current_action_name\']=' 636 .$GLOBALS['current_action_name']); 637 error_log('$GLOBALS[\'current_controller_name\']=' 638 .$GLOBALS['current_controller_name']); 639 error_log('$GLOBALS[\'current_controller_path\']=' 640 .$GLOBALS['current_controller_path']); 605 641 } 606 642 607 643 # Which layout should we use? 608 644 $layout_file = $this->determine_layout(); 609 645 error_log('layout_file="'.$layout_file.'"'); 610 646 # Check if there is any defined scaffolding to load 611 if( $this->controller_object->scaffold) {647 if(isset($this->controller_object->scaffold)) { 612 648 $scaffold = $this->controller_object->scaffold; 613 649 if(file_exists(TRAX_LIB_ROOT."/scaffold_controller.php")) { … … 659 695 $this->execute_before_filters(); 660 696 if(method_exists($this->controller_object, $this->action)) { 697 error_log('controller has method "'.$this->action.'"'); 661 698 $action = $this->action; 662 699 $this->controller_object->$action(); 663 700 } elseif(file_exists($this->views_path . "/" . $this->action . "." . $this->views_file_extention)) { 701 error_log('views file "'.$this->action.'"'); 664 702 $action = $this->action; 665 703 } elseif(method_exists($this->controller_object, "index")) { 704 error_log('calling index()'); 666 705 $this->controller_object->index(); 667 706 } else { 707 error_log('no action'); 668 708 $this->raise("No action responded to ".$this->action, "Unknown action", "404"); 669 709 } … … 671 711 672 712 # Find out if there was a redirect to some other page 673 if($this->controller_object->redirect_to) { 713 if(isset($this->controller_object->redirect_to) 714 && $this->controller_object->redirect_to != '') { 674 715 $this->redirect_to($this->controller_object->redirect_to); 675 716 } else { … … 678 719 } 679 720 680 if($this->controller_object->render_text != "") { 721 if(isset($this->controller_object->render_text) 722 && $this->controller_object->render_text != "") { 681 723 echo $this->controller_object->render_text; 682 724 } else { 683 725 # If this isn't a scaffolding then get the view file to include 684 if(! $scaffold) {726 if(!isset($scaffold)) { 685 727 # Normal processing of the view 686 if($this->controller_object->render_action) { 728 if(isset($this->controller_object->render_action) 729 && $this->controller_object->render_action != '' ) { 687 730 $this->view_file = $this->views_path . "/" . $this->controller_object->render_action . "." . $this->views_file_extention; 688 } elseif($action) { 731 } elseif(isset($action) 732 && $action != '') { 689 733 $this->view_file = $this->views_path . "/" . $action . "." . $this->views_file_extention; 690 734 } else { … … 701 745 702 746 # Grab all the html from the view to put into the layout 703 $content_for_layout .= ob_get_contents();747 $content_for_layout = ob_get_contents(); 704 748 ob_end_clean(); 705 749 … … 755 799 $this->layouts_path .= "/$extra_path"; 756 800 } 757 if(is_array($new_path)) { 801 if(isset($new_path) 802 && is_array($new_path)) { 758 803 $this->url_path = $new_path; 759 804 } … … 933 978 function determine_layout() { 934 979 # I guess you don't want any layout 935 // FIXME: Do we really want to test for null here? 936 // It might make more sense to test isset(...layout) 937 if($this->controller_object->layout == "null") { 980 if(!isset($this->controller_object->layout) 981 || $this->controller_object->layout == "null") { 938 982 return null; 939 983 } 940 984 # $layout will be the layout defined in the current controller 941 985 # or try to use the controller name for the layout 942 $layout = $this->controller_object->layout ? $this->controller_object->layout : $this->controller; 986 $layout = (isset($this->controller_object->layout) 987 && $this->controller_object->layout != '') 988 ? $this->controller_object->layout : $this->controller; 943 989 # Check if a method has been defined to determine the layout at runtime 944 990 if(method_exists($this->controller_object, $layout)) { … … 963 1009 // FIXME: this file isn't in the distribution so 964 1010 // this reference will fail 965 if(! $layout_file) {1011 if(!isset($layout_file)) { 966 1012 $layout_file = $this->default_layout_file; 967 1013 }
