BaseYii getAlias()

getAlias() public static method

Translates a path alias into an actual path.

The translation is done according to the following procedure:

  1. If the given alias does not start with '@', it is returned back without change;
  2. Otherwise, look for the longest registered alias that matches the beginning part of the given alias. If it exists, replace the matching part of the given alias with the corresponding registered path.
  3. Throw an exception or return false, depending on the $throwException parameter.

For example, by default '@yii' is registered as the alias to the Yii framework directory, say '/path/to/yii'. The alias '@yii/web' would then be translated into '/path/to/yii/web'.

If you have registered two aliases '@foo' and '@foo/bar'. Then translating '@foo/bar/config' would replace the part '@foo/bar' (instead of '@foo') with the corresponding registered path. This is because the longest alias takes precedence.

However, if the alias to be translated is '@foo/barbar/config', then '@foo' will be replaced instead of '@foo/bar', because '/' serves as the boundary character.

Note, this method does not check if the returned path exists or not.

See also setAlias().

public static string|boolean getAlias ( $alias, $throwException = true )
$alias string

The alias to be translated.

$throwException boolean

Whether to throw an exception if the given alias is invalid. If this is false and an invalid alias is given, false will be returned by this method.

return string|boolean

The path corresponding to the alias, false if the root alias is not previously registered.

throws yii\base\InvalidParamException

if the alias is invalid while $throwException is true.

doc_Yii
2016-10-30 16:50:27
Comments
Leave a Comment

Please login to continue.