forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
515 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Path Aliases | ||
============ | ||
|
||
> Note: This chapter is under development. | ||
Yii 2.0 expands the usage of path aliases to both file/directory paths and URLs. An alias | ||
must start with an `@` symbol so that it can be differentiated from file/directory paths and URLs. | ||
For example, the alias `@yii` refers to the Yii installation directory while `@web` contains the base URL for the currently running web application. Path aliases are supported in most places in the Yii core code. For example, `FileCache::cachePath` can accept both a path alias and a normal directory path. | ||
|
||
Path aliases are also closely related to class namespaces. It is recommended that a path | ||
alias should be defined for each root namespace so that Yii's class autoloader can be used without | ||
any further configuration. For example, because `@yii` refers to the Yii installation directory, | ||
a class like `yii\web\Request` can be autoloaded by Yii. If you use a third party library | ||
such as Zend Framework, you may define a path alias `@Zend` which refers to its installation | ||
directory and Yii will be able to autoload any class in this library. | ||
|
||
The following aliases are predefined by the core framework: | ||
|
||
- `@yii` - framework directory. | ||
- `@app` - base path of currently running application. | ||
- `@runtime` - runtime directory. | ||
- `@vendor` - Composer vendor directory. | ||
- `@webroot` - web root directory of currently running web application. | ||
- `@web` - base URL of currently running web application. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Autoloading | ||
=========== | ||
|
||
> Note: This chapter is under development. | ||
All classes, interfaces and traits are loaded automatically at the moment they are used. There's no need to use `include` or `require`. It is true for Composer-loaded packages as well as Yii extensions. | ||
|
||
Yii's autoloader works according to [PSR-4](https://github.com/php-fig/fig-standards/blob/master/proposed/psr-4-autoloader/psr-4-autoloader.md). | ||
That means namespaces, classes, interfaces and traits must correspond to file system paths and file names accordinly, except for root namespace paths that are defined by an alias. | ||
|
||
For example, if the standard alias `@app` refers to `/var/www/example.com/` then `\app\models\User` will be loaded from `/var/www/example.com/models/User.php`. | ||
|
||
Custom aliases may be added using the following code: | ||
|
||
```php | ||
Yii::setAlias('@shared', realpath('~/src/shared')); | ||
``` | ||
|
||
Additional autoloaders may be registered using PHP's standard `spl_autoload_register`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.