Changeset 284 for trunk/trax/vendor
- Timestamp:
- 02/18/07 13:04:07 (5 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/action_controller.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_controller.php
r269 r284 323 323 } elseif($key == "redirect_to") { 324 324 $this->redirect_to($value); 325 } elseif($key == "layout") { 326 $this->layout = $value; 327 $this->determine_layout(); 325 328 } else { 326 329 $this->$key = $value; … … 335 338 if(method_exists($this, $method_name)) { 336 339 # If the method exists, just call it 337 $result = call_user_func (array($this, $method_name), $parameters);340 $result = call_user_func_array(array($this, $method_name), $parameters); 338 341 } else { 339 342 if($method_name == "before_filter") { … … 578 581 579 582 include_once($this->controller_file); 580 if(class_exists($this->controller_class, false)) { 583 if(class_exists($this->controller_class, false)) { 584 $class = $this->controller_class; 585 $this->controller_object = new $class(); 586 } 587 588 if(is_object($this->controller_object)) { 581 589 582 $class = $this->controller_class; 583 $this->controller_object = new $class(); 584 585 if(is_object($this->controller_object)) { 586 587 $this->controller_object->controller = $this->controller; 588 $this->controller_object->action = $this->action; 589 $this->controller_object->controller_path = "$this->added_path/$this->controller"; 590 $this->controller_object->views_path = $this->views_path; 591 $this->controller_object->layouts_path = $this->layouts_path; 592 Trax::$current_controller_path = "$this->added_path/$this->controller"; 593 Trax::$current_controller_name = $this->controller; 594 Trax::$current_action_name = $this->action; 595 Trax::$current_controller_object =& $this->controller_object; 596 # Which layout should we use? 597 $layout_file = $this->controller_object->determine_layout(); 598 //error_log('using layout_file "'.$layout_file.'"'); 599 # Check if there is any defined scaffolding to load 600 if(isset($this->controller_object->scaffold)) { 601 $scaffold = $this->controller_object->scaffold; 602 if(file_exists(TRAX_LIB_ROOT."/scaffold_controller.php")) { 603 include_once(TRAX_LIB_ROOT."/scaffold_controller.php"); 604 $this->controller_object = new ScaffoldController($scaffold); 605 Trax::$current_controller_object =& $this->controller_object; 606 $render_options['scaffold'] = true; 607 if(!file_exists($layout_file)) { 608 # the generic scaffold layout 609 $layout_file = TRAX_LIB_ROOT . "/templates/scaffolds/layout.phtml"; 610 } 590 $this->controller_object->controller = $this->controller; 591 $this->controller_object->action = $this->action; 592 $this->controller_object->controller_path = "$this->added_path/$this->controller"; 593 $this->controller_object->views_path = $this->views_path; 594 $this->controller_object->layouts_path = $this->layouts_path; 595 Trax::$current_controller_path = "$this->added_path/$this->controller"; 596 Trax::$current_controller_name = $this->controller; 597 Trax::$current_action_name = $this->action; 598 Trax::$current_controller_object =& $this->controller_object; 599 # Which layout should we use? 600 $this->controller_object->determine_layout(); 601 # Check if there is any defined scaffolding to load 602 if(isset($this->controller_object->scaffold)) { 603 $scaffold = $this->controller_object->scaffold; 604 if(file_exists(TRAX_LIB_ROOT."/scaffold_controller.php")) { 605 include_once(TRAX_LIB_ROOT."/scaffold_controller.php"); 606 $this->controller_object = new ScaffoldController($scaffold); 607 Trax::$current_controller_object =& $this->controller_object; 608 $render_options['scaffold'] = true; 609 if(!file_exists($this->controller_object->layout_file)) { 610 # the generic scaffold layout 611 $this->controller_object->layout_file = TRAX_LIB_ROOT . "/templates/scaffolds/layout.phtml"; 611 612 } 612 613 } 613 } 614 } 615 616 # Include main application helper file 617 if(file_exists($this->application_helper_file)) { 618 include_once($this->application_helper_file); 619 } 620 621 # Include helper file for this controller 622 if(file_exists($this->helper_file)) { 623 include_once($this->helper_file); 624 } 625 626 if(is_object($this->controller_object)) { 614 } 615 616 # Include main application helper file 617 if(file_exists($this->application_helper_file)) { 618 include_once($this->application_helper_file); 619 } 620 621 # Include helper file for this controller 622 if(file_exists($this->helper_file)) { 623 include_once($this->helper_file); 624 } 627 625 628 626 # Include any extra helper files defined in this controller … … 650 648 # Call the controller method based on the URL 651 649 if($this->controller_object->execute_before_filters()) { 652 650 $controller_layout = null; 651 if(isset($this->controller_object->layout)) { 652 $controller_layout = $this->controller_object->layout; 653 } 653 654 if(method_exists($this->controller_object, $this->action)) { 654 655 //error_log('method '.$this->action.' exists, calling it'); … … 673 674 $this->raise("No action responded to ".$this->action, "Unknown action", "404"); 674 675 } 676 677 if(isset($this->controller_object->layout)) { 678 if($controller_layout != $this->controller_object->layout) { 679 # layout was set in the action need to redetermine the layout file to use. 680 $this->controller_object->determine_layout(); 681 } 682 } 683 675 684 $this->controller_object->execute_after_filters(); 676 685 … … 708 717 if(isset($this->controller_object->render_layout) 709 718 && ($this->controller_object->render_layout !== false) 710 && $ layout_file) {719 && $this->controller_object->layout_file) { 711 720 $locals['content_for_layout'] = $content_for_layout; 712 721 # render the layout 713 //error_log("rendering layout: $layout_file");714 if(!$this->controller_object->render_file($ layout_file, false, $locals)) {722 //error_log("rendering layout: ".$this->controller_object->layout_file); 723 if(!$this->controller_object->render_file($this->controller_object->layout_file, false, $locals)) { 715 724 # No layout template so just echo out whatever is in $content_for_layout 716 725 //echo "HERE"; … … 721 730 # $this->raise("No layout file found.", "Unknown layout", "404"); 722 731 # No layout template so just echo out whatever is in $content_for_layout 732 //error_log("no layout found: ".$this->controller_object->layout_file); 723 733 echo $content_for_layout; 724 734 } 725 } 735 } 726 736 } else { 727 737 $this->raise("Failed to instantiate controller object \"".$this->controller."\".", "ActionController Error", "500"); … … 734 744 if(!$this->keep_flash) { 735 745 # Nuke the flash 746 unset($_SESSION['flash']); 736 747 Session::unset_var('flash'); 737 748 } … … 763 774 function set_paths() { 764 775 if(is_array($this->url_path)) { 776 $test_path = null; 765 777 foreach($this->url_path as $path) { 766 if(file_exists($this->controllers_path . "/$path")) { 778 $test_path = (is_null($test_path) ? $path : "$test_path/$path"); 779 if(is_dir($this->controllers_path . "/$test_path")) { 767 780 $extra_path[] = $path; 768 781 } else { 782 $test_path = null; 769 783 $new_path[] = $path; 770 784 } … … 1189 1203 $layout_file = $default_layout_file; 1190 1204 } 1205 $this->layout_file = $layout_file; 1191 1206 return $layout_file; 1192 1207 }
