Add actionUrl() helper to backend controller

Used for generating URLs to the current controller
This commit is contained in:
Samuel Georges 2015-07-23 19:44:54 +10:00
parent 46bfa78cef
commit fc490b18e9
1 changed files with 21 additions and 0 deletions

View File

@ -298,6 +298,27 @@ class Controller extends Extendable
return false;
}
/**
* Returns a URL for this controller and supplied action.
*/
public function actionUrl($action = null, $path = null)
{
if ($action === null) {
$action = $this->action;
}
$class = get_called_class();
$uriPath = dirname(dirname(strtolower(str_replace('\\', '/', $class))));
$controllerName = strtolower(class_basename($class));
$url = $uriPath.'/'.$controllerName.'/'.$action;
if ($path) {
$url .= '/'.$path;
}
return Backend::url($url);
}
/**
* Invokes the current controller action without rendering a view,
* used by AJAX handler that may rely on the logic inside the action.