/** * Obtain an instance of the correct controller. * * @return an instance of SugarController */ function getController($module) { $class = ucfirst($module) . 'Controller'; if (file_exists('custom/modules/' . $module . '/controller.php')) { $customClass = 'Custom' . $class; require_once 'custom/modules/' . $module . '/controller.php'; if (class_exists($customClass)) { $controller = new $customClass(); } else { if (class_exists($class)) { $controller = new $class(); } } } elseif (file_exists('modules/' . $module . '/controller.php')) { require_once 'modules/' . $module . '/controller.php'; if (class_exists($class)) { $controller = new $class(); } } else { $controller = new SugarController(); } //setup the controller $controller->setup($module); return $controller; }
/** * @see SugarController::setup($module = '') */ public function setup($module = '') { $result = parent::setup($module); // bug 41860 fix if (!empty($_REQUEST['id'])) { $this->record = $_REQUEST['id']; } // end bugfix return $result; }
public function testsetup() { $SugarController = new SugarController(); $default_module = $SugarController->module; //first test with empty parameter and check for default values being used $SugarController->setup(''); $this->assertAttributeEquals($default_module, 'module', $SugarController); $this->assertAttributeEquals(null, 'target_module', $SugarController); //secondly test with module name and check for correct assignment. $SugarController->setup('Users'); $this->assertAttributeEquals('Users', 'module', $SugarController); $this->assertAttributeEquals(null, 'target_module', $SugarController); }
/** * Obtain an instance of the correct controller. * * @return an instance of SugarController */ function getController($module) { if (SugarAutoLoader::requireWithCustom("modules/{$module}/controller.php")) { $class = SugarAutoLoader::customClass(ucfirst($module) . 'Controller'); } else { SugarAutoLoader::requireWithCustom('include/MVC/Controller/SugarController.php'); $class = SugarAutoLoader::customClass('SugarController'); } if (class_exists($class, false)) { $controller = new $class(); } if (empty($controller)) { $controller = new SugarController(); } //setup the controller $controller->setup($module); return $controller; }