Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Tests if the action name changed after it got set.
  */
 public function testGetActionName()
 {
     $this->request->setActionName('actionNameTest');
     $this->assertEquals('actionNameTest', $this->request->getActionName(), 'Actionname changed.');
 }
Example #3
0
 /**
  * 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);
 }