Samuel Georges c8d8d4e931 Introduce new Cms helper
This is modeled after the Backend helper. Primarily used to generate URLs for the frontend, these are piped through the CmsController action. It would also be a good place to add a hook, if necessary later.
2016-08-20 14:43:49 +10:00

39 lines
800 B
PHP

<?php namespace Cms\Helpers;
use Url;
use Route;
/**
* CMS Helper
*
* @package october\cms
* @see \Cms\Facades\Cms
* @author Alexey Bobkov, Samuel Georges
*/
class Cms
{
protected static $actionExists = null;
/**
* Returns a URL in context of the Frontend
*/
public function url($path = null)
{
$routeAction = 'Cms\Classes\CmsController@run';
if (self::$actionExists === null) {
self::$actionExists = Route::getRoutes()->getByAction($routeAction) !== null;
}
if (substr($path, 0, 1) == '/') {
$path = substr($path, 1);
}
if (self::$actionExists) {
return Url::action($routeAction, ['slug' => $path]);
}
else {
return Url::to($path);
}
}
}