From f5da8366baa474253241cdbd3784deb5bb007dba Mon Sep 17 00:00:00 2001 From: fangliang Date: Tue, 1 Sep 2015 20:39:36 +0800 Subject: [PATCH 1/3] init translate --- docs/guide-zh-CN/tutorial-shared-hosting.md | 103 ++++++++++++++++++++++++ docs/guide-zh-CN/tutorial-start-from-scratch.md | 55 +++++++++++++ docs/guide-zh-CN/tutorial-template-engines.md | 49 +++++++++++ 3 files changed, 207 insertions(+) create mode 100644 docs/guide-zh-CN/tutorial-shared-hosting.md create mode 100644 docs/guide-zh-CN/tutorial-start-from-scratch.md create mode 100644 docs/guide-zh-CN/tutorial-template-engines.md diff --git a/docs/guide-zh-CN/tutorial-shared-hosting.md b/docs/guide-zh-CN/tutorial-shared-hosting.md new file mode 100644 index 0000000..6aebf44 --- /dev/null +++ b/docs/guide-zh-CN/tutorial-shared-hosting.md @@ -0,0 +1,103 @@ +共享托管环境 +========================== + +共享的托管环境常常会对目录结构以及配置文件有较多的限制。然而,在大多数情况下,你仍可以通过少量的修改以在共享托管环境下运行 Yii 2.0。 + +部署一个基础应用模板 +--------------------------- + +由于共享托管环境往往只有一个 webroot,如果可能,请优先使用基础项目模板( basic project template )构建你的应用程序。参考 [安装 Yii 章节](start-installation.md)在本地安装基础项目模板。当你让应用程序在本地正常运行后,我们将要做少量的修改以让它可以在共享托管服务器运行。 + +### 重命名 webroot + +用FTP或者其他的工具连接到你的托管服务器,你可能看到类似如下的目录结构: + +``` +config +logs +www +``` + +在以上,`www` 是你的 web 服务器的 webroot 目录。不同的托管环境下名称可能各不相同,通常是类似: `www`, `htdocs`, 和 `public_html` 之类的名称。 + +对于我们的基础项目模板而言,其 webroot 名为 `web` 。 在你上传你的应用程序到 web 服务器上去之前,将你的本地 webroot 重命名以匹配服务器。 即: 从 `web` 改为 `www`, `public_html` 或者其他你的托管环境的 webroot 名称。 + + +### FTP 根目录可写 + +如果你有 FTP 根目录的写权限,即,有 `config`, `logs` 和 `www` 的根目录,那么,如本地根目录相同的结构上传 `assets`, `commands` 等目录。 + +### 增加 web 服务器的额外配置 + +如果你的 web 服务器是 Apache,你需要增加一个包含如下内容的 `.htaccess` 文件到你的 `web` 目录(或者 `public_html` 根据实际情况而定,是你的 `index.php` 文件所在的目录)。 + +``` +Options +FollowSymLinks +IndexIgnore */* + +RewriteEngine on + +# if a directory or a file exists, use it directly +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d + +# otherwise forward it to index.php +RewriteRule . index.php +``` + +对于nginx而言,你不需要额外的配置文件。 + +### 检查环境要求 + +为了运行 Yii ,你的 web 服务器必须匹配它的环境要求。最低的要求必须是 PHP 5.4。为了检查环境配置,将 `requirements.php` 从你的根目录拷贝到 webroot 目录,并通过浏览器输入 URL `http://example.com/requirements.php` 运行它。最后,检查结束后别忘了删除这个文件哦! + +部署一个高级应用程序模板 +--------------------------------- + +部署一个高级应用程序到共享的托管环境比基础应用要麻烦的原因在于它包含有两个 webroot 目录,而共享的托管环境不支持两个。对于这种情况,我们需要调整目录结构。 + +### 将入口文件移动到同一个 webroot + +首先我们需要一个 webroot 目录,如[重命名 webroot](#renaming-webroot)一节所述,创建一个新的跟你的托管环境 webroot 同名的目录,如类似 `www` 或者 `public_html` 的名字。创建如下的目录结构,其中 `www` 目录指代你刚刚创建的 webroot 目录。 + +``` +www + admin +backend +common +console +environments +frontend +... +``` + +`www` 目录是我们的前台目录,所以将 `frontend/web` 里面的内容移到这个目录。 将 `backend/web` 里面的内容移到 `www/admin` 目录。对于每种情况下,你需要调整`index.php` 和 `index-test.php` 里面引用的目录结构。 + +### 分离 Session 和 Cookie + +通常情况下,backend 和 frontend 运行在不同的域下,当我们将其都移到同一个域时, frontend 和 backend 将会共享相同的 cookie,这样会造成冲突。为了修复这个问题,如下调整 backend 的应用程序配置文件 `backend/config/main.php`: + +```php +'components' => [ + 'request' => [ + 'csrfParam' => '_backendCSRF', + 'csrfCookie' => [ + 'httpOnly' => true, + 'path' => '/admin', + ], + ], + 'user' => [ + 'identityCookie' => [ + 'name' => '_backendIdentity', + 'path' => '/admin', + 'httpOnly' => true, + ], + ], + 'session' => [ + 'name' => 'BACKENDSESSID', + 'cookieParams' => [ + 'path' => '/admin', + ], + ], +], +``` diff --git a/docs/guide-zh-CN/tutorial-start-from-scratch.md b/docs/guide-zh-CN/tutorial-start-from-scratch.md new file mode 100644 index 0000000..36ad3ba --- /dev/null +++ b/docs/guide-zh-CN/tutorial-start-from-scratch.md @@ -0,0 +1,55 @@ +Creating your own Application structure +======================================= + +> Note: This section is under development. + +While the [basic](https://github.com/yiisoft/yii2-app-basic) and [advanced](https://github.com/yiisoft/yii2-app-advanced) +project templates are great for most of your needs, you may want to create your own project template with which +to start your projects. + +Project templates in Yii are simply repositories containing a `composer.json` file, and registered as a Composer package. +Any repository can be identified as a Composer package, making it installable via `create-project` Composer command. + +Since it's a bit too much to start building your entire template from scratch, it is better to use one of the built-in +templates as a base. Let's use the basic template here. + +Clone the Basic Template +---------------------------------------- + +The first step is to clone the basic Yii template's Git repository: + +```bash +git clone git@github.com:yiisoft/yii2-app-basic.git +``` + +Then wait for the repository to be downloaded to your computer. Since the changes made to the template won't be pushed back, you can delete the `.git` diretory and all +of its contents from the download. + +Modify the Files +------------ + +Next, you'll want to modify the `composer.json` to reflect your template. Change the `name`, `description`, `keywords`, `homepage`, `license`, and `support` values +to describe your new template. Also adjust the `require`, `require-dev`, `suggest`, and other options to match your template's requirements. + +> Note: In the `composer.json` file, use the `writable` parameter under `extra` to specify +> per file permissions to be set after an application is created using the template. + +Next, actually modify the structure and contents of the application as you would like the default to be. Finally, update the README file to be applicable to your template. + +Make a Package +-------------- + +With the template defined, create a Git repository from it, and push your files there. If you're going to open source your template, [Github](http://github.com) is the best place to host it. If you intend to keep your template non-collaborative, any Git repository site will do. + +Next, you need to register your package for Composer's sake. For public templates, the package should be registered at [Packagist](https://packagist.org/). +For private templates, it is a bit more tricky to register the package. For instructions, see the [Composer documentation](https://getcomposer.org/doc/05-repositories.md#hosting-your-own). + +Use the Template +------ + +That's all that's required to create a new Yii project template. Now you can create projects using your template: + +``` +composer global require "fxp/composer-asset-plugin:~1.0.0" +composer create-project --prefer-dist --stability=dev mysoft/yii2-app-coolone new-project +``` diff --git a/docs/guide-zh-CN/tutorial-template-engines.md b/docs/guide-zh-CN/tutorial-template-engines.md new file mode 100644 index 0000000..56f8def --- /dev/null +++ b/docs/guide-zh-CN/tutorial-template-engines.md @@ -0,0 +1,49 @@ +Using template engines +====================== + +By default, Yii uses PHP as its template language, but you can configure Yii to support other rendering engines, such as +[Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/) available as extensions. + +The `view` component is responsible for rendering views. You can add a custom template engine by reconfiguring this +component's behavior: + +```php +[ + 'components' => [ + 'view' => [ + 'class' => 'yii\web\View', + 'renderers' => [ + 'tpl' => [ + 'class' => 'yii\smarty\ViewRenderer', + //'cachePath' => '@runtime/Smarty/cache', + ], + 'twig' => [ + 'class' => 'yii\twig\ViewRenderer', + 'cachePath' => '@runtime/Twig/cache', + // Array of twig options: + 'options' => [ + 'auto_reload' => true, + ], + 'globals' => ['html' => '\yii\helpers\Html'], + 'uses' => ['yii\bootstrap'], + ], + // ... + ], + ], + ], +] +``` + +In the code above, both Smarty and Twig are configured to be useable by the view files. But in order to get these extensions into your project, you need to also modify +your `composer.json` file to include them, too: + +``` +"yiisoft/yii2-smarty": "*", +"yiisoft/yii2-twig": "*", +``` +That code would be added to the `require` section of `composer.json`. After making that change and saving the file, you can install the extensions by running `composer update --prefer-dist` in the command-line. + +For details about using concrete template engine please refer to its documentation: + +- [Twig guide](https://github.com/yiisoft/yii2-twig/tree/master/docs/guide) +- [Smarty guide](https://github.com/yiisoft/yii2-smarty/tree/master/docs/guide) \ No newline at end of file From 42ef517721091c83ed8ba5c43e227a7e2a6ac7ba Mon Sep 17 00:00:00 2001 From: fangliang Date: Tue, 1 Sep 2015 21:09:45 +0800 Subject: [PATCH 2/3] translated start-from-sratch --- docs/guide-zh-CN/tutorial-start-from-scratch.md | 40 +++++++++++-------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/docs/guide-zh-CN/tutorial-start-from-scratch.md b/docs/guide-zh-CN/tutorial-start-from-scratch.md index 36ad3ba..43c1f67 100644 --- a/docs/guide-zh-CN/tutorial-start-from-scratch.md +++ b/docs/guide-zh-CN/tutorial-start-from-scratch.md @@ -1,53 +1,47 @@ -Creating your own Application structure +创建你自己的应用程序结构 ======================================= -> Note: This section is under development. +> 注:本章节正在开发中。 -While the [basic](https://github.com/yiisoft/yii2-app-basic) and [advanced](https://github.com/yiisoft/yii2-app-advanced) -project templates are great for most of your needs, you may want to create your own project template with which -to start your projects. +虽然 [basic](https://github.com/yiisoft/yii2-app-basic) 和 [advanced](https://github.com/yiisoft/yii2-app-advanced) 项目模板能够满足你的大部分需求,但是,你仍有可能需要创建你自己的项目模板来开始项目。 -Project templates in Yii are simply repositories containing a `composer.json` file, and registered as a Composer package. -Any repository can be identified as a Composer package, making it installable via `create-project` Composer command. +Yii 的项目模板是一个包含 `composer.json` 文件的仓库,并被注册为一个 Composer package。任何一个仓库都可以被标识为一个 Composer package,只要让其可以通过 `create-project` Composer 命令安装。 -Since it's a bit too much to start building your entire template from scratch, it is better to use one of the built-in -templates as a base. Let's use the basic template here. +由于完全从新创建一个你自己的模板工作量有点大,最好的方式是以一个内建模板为基础。这里,我们使用基础应用模板。 -Clone the Basic Template +克隆基础模板 ---------------------------------------- -The first step is to clone the basic Yii template's Git repository: +第一步是从 Git 仓库克隆 Yii 的基础模板: ```bash git clone git@github.com:yiisoft/yii2-app-basic.git ``` -Then wait for the repository to be downloaded to your computer. Since the changes made to the template won't be pushed back, you can delete the `.git` diretory and all -of its contents from the download. +等待仓库下载到你的电脑。因为为调整到你自己的模板所产生的修改不会被 push 回,你可以删除下载下来的 `.git` 目录及其内容。 -Modify the Files +修改文件 ------------ Next, you'll want to modify the `composer.json` to reflect your template. Change the `name`, `description`, `keywords`, `homepage`, `license`, and `support` values to describe your new template. Also adjust the `require`, `require-dev`, `suggest`, and other options to match your template's requirements. +接下来,你需要修改 `composer.json` 以配置你自己的模板。修改 `name`, `description`, `keywords`, `homepage`, `license`, 和 `support` 的值来描述你自己的模板。同样,调整 `require`, `require-dev`, `suggest` 和其他的参数来匹配你模板的环境需求。 -> Note: In the `composer.json` file, use the `writable` parameter under `extra` to specify -> per file permissions to be set after an application is created using the template. +> 注意:在 `composer.json` 文件中,使用 `extra` 下的 `writeable` 参数来指定使用模板创建的应用程序后需要设置文件权限的文件列表。 -Next, actually modify the structure and contents of the application as you would like the default to be. Finally, update the README file to be applicable to your template. +接下来,真正的修改你的应用程序默认的目录结构和内容。最后,更新 README 文件以符合你的模板。 -Make a Package +发布一个 Package -------------- -With the template defined, create a Git repository from it, and push your files there. If you're going to open source your template, [Github](http://github.com) is the best place to host it. If you intend to keep your template non-collaborative, any Git repository site will do. +模板调整好后,通过其创建一个 Git 仓库并提交你的代码。如果你希望将你的应用程序模板开源,[Github]() 将是最好的托管服务。如果你不喜欢其他的人来跟你一起协作,你可以使用任意的 Git 仓库服务。 -Next, you need to register your package for Composer's sake. For public templates, the package should be registered at [Packagist](https://packagist.org/). -For private templates, it is a bit more tricky to register the package. For instructions, see the [Composer documentation](https://getcomposer.org/doc/05-repositories.md#hosting-your-own). +接下来,你需要为 Composer 注册你的 package。对于公有的模板,你可以将 package 注册到 [Packagist](https://packagist.org/)。对于私有的模板,注册 package 将会麻烦一点。参考 [Composer documentation](https://getcomposer.org/doc/05-repositories.md#hosting-your-own) 获取更多的指示。 -Use the Template +使用模板 ------ -That's all that's required to create a new Yii project template. Now you can create projects using your template: +以上就是为了创建一个新的 Yii 项目模板你需要做的事情。现在,你可以使用你自己的模板创建项目了: ``` composer global require "fxp/composer-asset-plugin:~1.0.0" From a763bff9e8af6f5544b14b00dec81b35f450a64e Mon Sep 17 00:00:00 2001 From: fangliang Date: Tue, 1 Sep 2015 21:18:20 +0800 Subject: [PATCH 3/3] translated template-engines --- docs/guide-zh-CN/tutorial-template-engines.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/guide-zh-CN/tutorial-template-engines.md b/docs/guide-zh-CN/tutorial-template-engines.md index 56f8def..370a097 100644 --- a/docs/guide-zh-CN/tutorial-template-engines.md +++ b/docs/guide-zh-CN/tutorial-template-engines.md @@ -1,11 +1,9 @@ -Using template engines +使用模板引擎 ====================== -By default, Yii uses PHP as its template language, but you can configure Yii to support other rendering engines, such as -[Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/) available as extensions. +默认情况下,Yii 使用 PHP 作为其默认的模板引擎语言,但是,你可以配置 Yii 以扩展的方式支持其他的渲染引擎,比如 [Twig](http://twig.sensiolabs.org/) 或 [Smarty](http://www.smarty.net/)等。 -The `view` component is responsible for rendering views. You can add a custom template engine by reconfiguring this -component's behavior: +组件 `view` 就是用于渲染视图的。你可以重新配置这个组件的行为以增加一个自定义的模板引擎。 ```php [ @@ -34,16 +32,16 @@ component's behavior: ] ``` -In the code above, both Smarty and Twig are configured to be useable by the view files. But in order to get these extensions into your project, you need to also modify -your `composer.json` file to include them, too: +在上述的代码中, Smarty 和 Twig 都被配置以让视图文件使用。但是,为了让扩展安装到项目中,你同样需要修改你的 `composer.json` 文件,如下: ``` "yiisoft/yii2-smarty": "*", "yiisoft/yii2-twig": "*", ``` -That code would be added to the `require` section of `composer.json`. After making that change and saving the file, you can install the extensions by running `composer update --prefer-dist` in the command-line. -For details about using concrete template engine please refer to its documentation: +上述代码需要增加到 `composer.json` 的 `require` 节中。在做了上述修改,并保存后,你可以运行 `composer update --prefer-dist` 命令来安装扩展。 + +对于特定模板引擎的使用详细,请参考其文档: - [Twig guide](https://github.com/yiisoft/yii2-twig/tree/master/docs/guide) -- [Smarty guide](https://github.com/yiisoft/yii2-smarty/tree/master/docs/guide) \ No newline at end of file +- [Smarty guide](https://github.com/yiisoft/yii2-smarty/tree/master/docs/guide)