/** * 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; }
/** * Fills the request object with the best matched route. */ public function execute() { $this->request->setModuleName(DEFAULT_MODULE); $this->request->setControllerName('index'); $this->request->setActionName('index'); $this->fillQuery(); $query = $this->getQuery(); if (!empty($query)) { $result = $this->match($query); $this->updateRequest(reset($result)); } }
/** * Tests if the right POST parameter gets given back. */ public function testGetPost() { $_POST['username'] = '******'; $this->assertEquals('testuser', $this->request->getPost('username'), 'The request object didnt returned the POST parameter.'); }
/** * 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); }