lithium\net\http\Router::formatters()

public static method

Used to get or set an array of named formatter closures, which are used to format route parameters when generating URLs. For example, for controller/action parameters to be dashed instead of underscored or camelBacked, you could do the following:

use lithium\util\Inflector;

Router::formatters([
    'controller' => function($value) { return Inflector::slug($value); },
    'action' => function($value) { return Inflector::slug($value); }
]);

Note: Because formatters are copied to Route objects on an individual basis, make sure you append custom formatters before connecting new routes.

Parameters

  • array $formatters

    An array of named formatter closures to append to (or overwrite) the existing list.

Returns

array

Returns the formatters array.

Source

	public static function formatters(array $formatters = []) {
		if (!static::$_formatters) {
			static::$_formatters = [
				'args' => function($value) {
					return is_array($value) ? join('/', $value) : $value;
				},
				'controller' => function($value) {
					if (strpos($value, '\\')) {
						$value = explode('\\', $value);
						$value = end($value);
					}
					return Inflector::underscore($value);
				}
			];
		}
		if ($formatters) {
			static::$_formatters = array_filter($formatters + static::$_formatters);
		}
		return static::$_formatters;
	}