Pop\Mvc\Router::getAction PHP Method

getAction() public method

Get action from request within the current controller
public getAction ( ) : string
return string
    public function getAction()
    {
        $action = null;
        if (null !== $this->controller && null !== $this->controller->getRequest()) {
            // If the URI is root '/', then set to 'index'
            if ($this->controller->getRequest()->getRequestUri() == '/') {
                $action = 'index';
                // Else, figure out the action from the path stems
            } else {
                if ($this->controller->getRequest()->getPath(0) != '') {
                    $path = $this->controller->getRequest()->getPath();
                    $basePath = explode('/', substr($this->basePath, 1));
                    $pathDiff = array_values(array_diff($path, $basePath));
                    if (isset($pathDiff[0])) {
                        $realBasePath = substr($this->controller->getRequest()->getBasePath(), -1) == '/' ? substr($this->controller->getRequest()->getBasePath(), 0, -1) : $this->controller->getRequest()->getBasePath();
                        $this->controller->getRequest()->setRequestUri('/' . implode('/', $pathDiff), $realBasePath);
                        $action = $pathDiff[0];
                    }
                }
            }
        }
        return $action;
    }

Usage Example

Exemplo n.º 1
0
 public function testAction()
 {
     $r = new Router(array('/' => 'Pop\\Mvc\\Controller'));
     $r->route(new Project(new Config(array())));
     $this->assertEquals('index', $r->getAction());
 }
All Usage Examples Of Pop\Mvc\Router::getAction