Index: C:/dev/xebidy/Xebidy/sapphire/core/control/Director.php =================================================================== --- C:/dev/xebidy/Xebidy/sapphire/core/control/Director.php (revision 91) +++ C:/dev/xebidy/Xebidy/sapphire/core/control/Director.php (working copy) @@ -70,7 +70,7 @@ foreach($patternParts as $i => $part) { $part = trim($part); if(isset($part[0]) && $part[0] == '$') { - $arguments[substr($part,1)] = isset($urlParts[$i]) ? $urlParts[$i] : null; + $arguments[substr($part,1)] = isset($urlParts[$i]) ? $urlParts[$i] : null; if($part == '$Controller' && !class_exists($arguments['Controller'])) { $matched = false; break; @@ -95,13 +95,13 @@ } if(isset($_REQUEST['debug'])) Debug::message("Using controller $controller"); - if(isset($arguments['Action'])) { - $arguments['Action'] = str_replace('-','',$arguments['Action']); - } + if(isset($arguments['Action'])) { + $arguments['Action'] = str_replace('-','',$arguments['Action']); + } if(isset($arguments['Action']) && ClassInfo::exists($controller.'_'.$arguments['Action'])) $controller = $controller.'_'.$arguments['Action']; - - Director::$urlParams = $arguments; + + Director::$urlParams = $arguments; $controllerObj = new $controller(); $controllerObj->setURLParams($arguments); Index: C:/dev/xebidy/Xebidy/sapphire/core/control/Controller.php =================================================================== --- C:/dev/xebidy/Xebidy/sapphire/core/control/Controller.php (revision 91) +++ C:/dev/xebidy/Xebidy/sapphire/core/control/Controller.php (working copy) @@ -29,10 +29,10 @@ */ protected $baseInitCalled = false; - function run($requestParams) { + function run($requestParams) { if(isset($_GET['debug_profile'])) Profiler::mark("Controller", "run"); - $this->requestParams = $requestParams; + $this->requestParams = $requestParams; $this->action = isset($this->urlParams['Action']) ? str_replace("-","_",$this->urlParams['Action']) : "index"; // Init @@ -44,11 +44,11 @@ foreach($this->requestParams as $paramName => $paramVal) { if(substr($paramName,0,7) == 'action_') { // Cleanup action_, _x and _y from image fields - $funcName = preg_replace(array('/^action_/','/_x$|_y$/'),'',$paramName); + $funcName = preg_replace(array('/^action_/','/_x$|_y$/'),'',$paramName); + break; } } - // Form handler if(isset($this->requestParams['executeForm']) && is_string($this->requestParams['executeForm'])) { Form::set_current_action($funcName); @@ -91,7 +91,7 @@ if($funcName) $form->setButtonClicked($funcName); - }else{ + } else { user_error("No form ({Session::get('CMSMain.currentPage')}) returned by $formController->class->$_REQUEST[executeForm]", E_USER_WARNING); } if(isset($_GET['debug_profile'])) Profiler::unmark("Controller", "populate form"); @@ -122,7 +122,7 @@ // Normal action } else { if(!isset($funcName)) $funcName = $this->action; - + if(isset($_GET['debug_controller'])) Debug::show("attempting to execute $funcName"); if(method_exists($this, $funcName)) { if(isset($_GET['debug_controller'])) Debug::show("Found function $funcName on the $this->class controller"); Index: C:/dev/xebidy/Xebidy/sapphire/core/control/ModelController.php =================================================================== --- C:/dev/xebidy/Xebidy/sapphire/core/control/ModelController.php (revision 0) +++ C:/dev/xebidy/Xebidy/sapphire/core/control/ModelController.php (revision 0) @@ -0,0 +1,38 @@ +init(); + return $this->getNestedController()->run($requestParams); + } + + public function init() { + Versioned::choose_site_stage(); + } + + public function getNestedController() { + $child = null; + $Controller = $this->urlParams['Controller']; + if($this->urlParams['Controller']) { + $ID = $this->urlParams['ID']; + if (ClassInfo::exists($Controller) && is_numeric($ID) ) { + $child = DataObject::get_by_id($Controller, $ID); + if(isset($_REQUEST['debug'])) Debug::message("Found $Controller #$ID."); + } + } + + $controllerClass = $Controller."_Controller"; + if(ClassInfo::exists($controllerClass)) { + if(isset($_REQUEST['debug'])) Debug::message("Using $controllerClass with $child #$ID."); + $controller = new $controllerClass($child); + } else { + $controller = new $Controller(); + } + $controller->setURLParams($this->urlParams); + return $controller; + } + +} + +?> \ No newline at end of file