Skip to content

Commit

Permalink
guide wip [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangxue committed Apr 29, 2014
1 parent a620342 commit 5b8cf20
Show file tree
Hide file tree
Showing 46 changed files with 515 additions and 372 deletions.
50 changes: 26 additions & 24 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ Getting Started
* [Starting with Advanced App](start-advanced.md) - Best for developing an enterprise application by a team
* [Starting from Scratch](start-scratch.md) - Learning more in-depth details of creating a Yii application step-by-step


Basic Concepts
--------------

* [Object Properties](basic-properties.md)
* [Events](basic-events.md)
* [Behaviors](basic-behaviors.md)
* [Object Configurations](basic-configs.md)
* **TBD** [Class Autoloading](basic-autoloading.md)
* **TBD** [Path Aliases](basic-alias.md)
* [Class Autoloading](basic-autoloading.md)
* [Path Aliases](basic-alias.md)
* **TBD** [Extensions](basic-extensions.md)
* [Service Locator](basic-service-locator.md)
* **TBD** [Dependency Injection Container](basic-di-container.md)
* [Dependency Injection Container](basic-di-container.md)


Basic Structure
Expand Down Expand Up @@ -63,6 +64,19 @@ Handling Requests
* **TBD** [Filtering](runtime-filtering.md)


Working with Databases
----------------------

* [Data Access Objects](db-dao.md) - Connecting to a database, basic queries, transactions and schema manipulation
* [Query Builder](db-query-builder.md) - Querying the database using a simple abstraction layer
* [Active Record](db-active-record.md) - The active record ORM, retrieving and manipulating records and defining relations
* [Migrations](db-migrations.md) - Version control your databases in a team development environment
* **TBD** [Sphinx](db-sphinx.md)
* **TBD** [Redis](db-redis.md)
* **TBD** [MongoDB](db-mongodb.md)
* **TBD** [ElasticSearch](db-elastic-search.md)


Collecting Inputs
-----------------

Expand All @@ -83,19 +97,6 @@ Presenting Data
* [Managing Assets](output-assets.md)


Working with Database
---------------------

* [Data Access Objects](db-dao.md) - Connecting to a database, basic queries, transactions and schema manipulation
* [Query Builder](db-query-builder.md) - Querying the database using a simple abstraction layer
* [Active Record](db-active-record.md) - The active record ORM, retrieving and manipulating records and defining relations
* [Migrations](db-migrations.md)
* **TBD** [Sphinx](db-sphinx.md)
* **TBD** [Redis](db-redis.md)
* **TBD** [MongoDB](db-mongodb.md)
* **TBD** [ElasticSearch](db-elastic-search.md)


Security
--------

Expand Down Expand Up @@ -130,6 +131,14 @@ RESTful Web Services
* **TBD** [Testing](rest-testing.md)


Development Tools
-----------------

* [Debug Toolbar and Debugger](tool-debugger.md)
* [Generating Code using Gii](tool-gii.md)
* **TBD** [Generating API Documentation](tool-api-doc.md)


Testing
-------

Expand All @@ -151,14 +160,6 @@ Extending Yii
* [Using Composer](extend-using-composer.md)


Development Tools
-----------------

* [Debug Toolbar and Debugger](tool-debugger.md)
* [Generating Code using Gii](tool-gii.md)
* **TBD** [Generating API Documentation](tool-api-doc.md)


Special Topics
--------------

Expand Down Expand Up @@ -192,6 +193,7 @@ Widgets
Helpers
-------

* [Overview](helper-overview.md)
* **TBD** [ArrayHelper](helper-array.md)
* **TBD** [Html](helper-html.md)
* **TBD** [Url](helper-url.md)
Expand Down
25 changes: 25 additions & 0 deletions docs/guide/basic-aliases.md
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.

19 changes: 19 additions & 0 deletions docs/guide/basic-autoloading.md
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`.
44 changes: 44 additions & 0 deletions docs/guide/basic-configs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
Configuration
=============

> Note: This chapter is under development.
Object Configuration
--------------------

The [[yii\base\Object|Object]] class introduces a uniform way of configuring objects. Any descendant class
of [[yii\base\Object|Object]] should declare its constructor (if needed) in the following way so that
it can be properly configured:

```php
class MyClass extends \yii\base\Object
{
public function __construct($param1, $param2, $config = [])
{
// ... initialization before configuration is applied

parent::__construct($config);
}

public function init()
{
parent::init();

// ... initialization after configuration is applied
}
}
```

In the above example, the last parameter of the constructor must take a configuration array
which contains name-value pairs that will be used to initialize the object's properties at the end of the constructor.
You can override the `init()` method to do initialization work after the configuration is applied.

By following this convention, you will be able to create and configure new objects
using a configuration array like the following:

```php
$object = Yii::createObject([
'class' => 'MyClass',
'property1' => 'abc',
'property2' => 'cde',
], [$param1, $param2]);
```


Yii applications rely upon components to perform most of the common tasks, such as connecting to a database, routing browser
requests, and handling sessions. How these stock components behave can be adjusted by *configuring* your Yii application.
The majority of components have sensible default settings, so it's unlikely that you'll do a lot of configuration. Still, there are some mandatory configuration settings that you will have to establish, such as the database connection.
Expand Down
Loading

0 comments on commit 5b8cf20

Please sign in to comment.