/** * Loads controller defined by the request object. * * @return \Ilch\Controller\Base */ protected function loadController() { $controllerName = $this->request->getControllerName(); $findSub = strpos($controllerName, '_'); $dir = ''; if ($findSub !== false) { $controllerParts = explode('_', $this->request->getControllerName()); $controllerName = $controllerParts[1]; $dir = ucfirst($controllerParts[0]) . '\\'; } if ($this->request->isAdmin()) { $controller = '\\Modules\\' . ucfirst($this->request->getModuleName()) . '\\Controllers\\Admin\\' . $dir . ucfirst($controllerName); } else { $controller = '\\Modules\\' . ucfirst($this->request->getModuleName()) . '\\Controllers\\' . $dir . ucfirst($controllerName); } //TODO: React properly for controllers / modules / actions that don't exist $controller = new $controller($this->layout, $this->view, $this->request, $this->router, $this->translator); $action = $this->request->getActionName() . 'Action'; $this->plugin->addPluginData('controller', $controller); $this->plugin->execute('BeforeControllerLoad'); if (method_exists($controller, 'init')) { $controller->init(); } if (method_exists($controller, $action)) { $controller->{$action}(); } return $controller; }
/** * Tests if the module name changed after it got set. */ public function testGetModuleName() { $this->request->setModuleName('moduleNameTest'); $this->assertEquals('moduleNameTest', $this->request->getModuleName(), 'Modulename changed.'); }
/** * Returns a full url for the current url with only the given parts changed * @param array $urlParts * @param bool $resetParams * @param bool $secure * @return string */ public function getCurrentUrl(array $urlParts = array(), $resetParams = true, $secure = false) { $currentUrlParts = array('module' => $this->request->getModuleName(), 'controller' => $this->request->getControllerName(), 'action' => $this->request->getActionName()); $urlParams = array_merge($currentUrlParts, $resetParams ? array() : $this->request->getParams(), $urlParts); return $this->getUrl($urlParams, null, $secure); }