예제 #1
0
 /**
  * Method to show the content.
  *
  * @return mixed
  * @throws \Exception If not supported request method or bad controller
  */
 public function render()
 {
     $conf = Registry::get('conf');
     if (Sapi::isCli() && $conf['environment'] == 'production') {
         $suffix = 'CliAction';
         $action = $this->request->fromCli()->get('action', 'index');
     } else {
         $suffix = 'Action';
         $bag = 'from' . ucfirst(strtolower($this->response->getMethod()));
         $action = $this->request->{$bag}()->get('action', 'index');
         if ($conf['app']['routeable'] === true) {
             $target = Registry::get('router')->find();
             if ($target instanceof \Pimf\Route\Target) {
                 $action = $target->getAction();
                 Request::$getData = new Param((array) Request::stripSlashesIfMagicQuotes(array_merge($target->getParams(), Request::$getData->getAll())));
             }
         }
     }
     $action = strtolower($action) . $suffix;
     if (method_exists($this, 'init')) {
         call_user_func(array($this, 'init'));
     }
     if (!method_exists($this, $action)) {
         throw new Bomb("no action '{$action}' defined at controller " . get_class($this));
     }
     return call_user_func(array($this, $action));
 }
예제 #2
0
 /**
  * Method to show the content.
  *
  * @return mixed
  * @throws \Exception If not supported request method or bad controller
  */
 public function render()
 {
     if (Sapi::isCli() && Config::get('environment') == 'production') {
         $suffix = 'CliAction';
         $action = $this->request->fromCli()->get('action', 'index');
     } else {
         $suffix = 'Action';
         if ($this->request->getMethod() != 'GET' && $this->request->getMethod() != 'POST') {
             $redirectUrl = new Value($this->env->REDIRECT_URL);
             $redirectUrl = $redirectUrl->deleteLeading('/')->deleteTrailing('/')->explode('/');
             $action = isset($redirectUrl[1]) ? $redirectUrl[1] : 'index';
         } else {
             $bag = sprintf('from%s', ucfirst(strtolower($this->request->getMethod())));
             $action = $this->request->{$bag}()->get('action', 'index');
         }
         if (Config::get('app.routeable') === true && $this->router instanceof \Pimf\Router) {
             $target = $this->router->find();
             if ($target instanceof \Pimf\Route\Target) {
                 $action = $target->getAction();
                 Request::$getData = new Param(array_merge($target->getParams(), Request::$getData->getAll()));
             }
         }
     }
     $action = strtolower($action) . $suffix;
     if (method_exists($this, 'init')) {
         call_user_func(array($this, 'init'));
     }
     if (!method_exists($this, $action)) {
         throw new Bomb("no action '{$action}' defined at controller " . get_class($this));
     }
     return call_user_func(array($this, $action));
 }