/** * redirect from a controller action to another URL. It's possible to * use variables as dynamic URL parts. call it like * self::redirect('Application::index', $var); which redirects to * /app/path/controller/action/{$var} * * @static * @param string $method name of class and action in static syntax like Application::index without brackets * @param string|array $params optional one value or an array of values to enhance the generated URL * @return bool */ public static function redirect($method, $params = null) { header('Location: ' . LVC::get()->url($method, $params)); return true; }
/** * generates an URI from a static class method with parameters * from uri('Application::index', $var) you get the URI * /app/path/controller/action/{$var} * * also accepts absolute paths like '/public/stylesheets/style.css' and directly returns them for convenience. * * @param string $method method name in static syntax like 'Application::index' * @param string|array $params single value or array of parameters * @return string the URI */ public function uri($method, $params = null) { if (is_string($method) && substr($method, 0, 1) === '/') { return $method; } if ($params && !is_array($params)) { $params = array($params); } $method = explode('::', $method); $controller = $method[0] == 'Application' ? '/' : '/' . LVC::camelCaseTo($method[0]); $action = $method[1] == 'index' ? '/' : '/' . LVC::camelCaseTo($method[1]); return $this->uri . ($controller == '/' && $action != '/' ? '' : $controller) . ($action == '/' ? '' : $action) . ($params ? ($controller == '/' && $action == '/' ? '' : '/') . implode('/', $params) : ''); }