Router::namedConfig PHP Method

namedConfig() public static method

Gets the current named parameter configuration values.
See also: Router::$_namedConfig
public static namedConfig ( ) : array
return array
    public static function namedConfig()
    {
        return static::$_namedConfig;
    }

Usage Example

示例#1
0
/**
 * Converts a matching route array into a url string. Composes the string url using the template
 * used to create the route.
 *
 * @param array $params The params to convert to a string url.
 * @return string Composed route string.
 */
	protected function _writeUrl($params) {
		if (isset($params['prefix'])) {
			$prefixed = $params['prefix'] . '_';
		}
		if (isset($prefixed, $params['action']) && strpos($params['action'], $prefixed) === 0) {
			$params['action'] = substr($params['action'], strlen($prefixed) * -1);
			unset($params['prefix']);
		}

		if (is_array($params['pass'])) {
			$params['pass'] = implode('/', array_map('rawurlencode', $params['pass']));
		}

		$namedConfig = Router::namedConfig();
		$separator = $namedConfig['separator'];

		if (!empty($params['named']) && is_array($params['named'])) {
			$named = array();
			foreach ($params['named'] as $key => $value) {
				if (is_array($value)) {
					$flat = Hash::flatten($value, '][');
					foreach ($flat as $namedKey => $namedValue) {
						$named[] = $key . "[$namedKey]" . $separator . rawurlencode($namedValue);
					}
				} else {
					$named[] = $key . $separator . rawurlencode($value);
				}
			}
			$params['pass'] = $params['pass'] . '/' . implode('/', $named);
		}
		$out = $this->template;

		$search = $replace = array();
		foreach ($this->keys as $key) {
			$string = null;
			if (isset($params[$key])) {
				$string = $params[$key];
			} elseif (strpos($out, $key) != strlen($out) - strlen($key)) {
				$key .= '/';
			}
			$search[] = ':' . $key;
			$replace[] = $string;
		}
		$out = str_replace($search, $replace, $out);

		if (strpos($this->template, '*')) {
			$out = str_replace('*', $params['pass'], $out);
		}
		$out = str_replace('//', '/', $out);
		return $out;
	}
All Usage Examples Of Router::namedConfig