Development

Documentation/zh_CN/book/1.0/05-Configuring-Symfony (diff)

You must first sign up to be able to contribute.

Changes between Version 2 and Version 3 of Documentation/zh_CN/book/1.0/05-Configuring-Symfony

Show
Ignore:
Author:
Le.Jiang (IP: 218.83.87.222)
Timestamp:
03/22/07 16:01:58 (11 years ago)
Comment:

updated translation

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/zh_CN/book/1.0/05-Configuring-Symfony

    v2 v3  
    321321------------ 
    322322 
    323 During the course of application development, you will probably need to keep several sets of configuration in parallel. For instance, you will need to have the connection settings for your tests database available during development, and the ones for your real data available for production. To answer the need of concurrent configurations, symfony offers different environments. 
     323在开发应用程序的过程中,你可能同时需要好几套配置信息。例如,开发中的用来测试的数据库配置信息,还有生产环境的正式的数据库配置信息。symfony为满足同时使用不同配置信息的需求,提供了不同的环境。 
    324324 
    325325### 什么是环境? What Is an Environment? 
    326326 
    327 An application can run in various environments. The different environments share the same PHP code (apart from the front controller), but can have completely different configurations. For each application, symfony provides three default environments: production (`prod`), test (test), and development (dev). You're also free to add as many custom environments as you wish. 
    328  
    329 So basically, environments and configuration are synonyms. For instance, a test environment will log alerts and errors, while a `prod` environment will only log errors. Cache acceleration is often deactivated in the `dev` environment, but activated in the `test` and `prod` environments. The `dev` and `test` environments may need test data, stored in a database distinct from the one used in the production environment. So the database configuration will be different between the two environments. All environments can live together on the same machine, although a production server generally contains only the `prod` environment. 
    330  
    331 In the `dev` environment, the logging and debugging settings are all enabled, since maintenance is more important than performance. On the contrary, the prod environment has settings optimized for performance by default, so the production configuration turns off many features. A good rule of thumb is to navigate in the development environment until you are satisfied with the feature you are working on, and then switch to the production environment to check its speed. 
    332  
    333 The test environment differs from the dev and prod environment in other ways. You interact with this environment solely through the command line for the purpose of functional testing and batch scripting. Consequently, the test environment is close to the production one, but it is not accessed through a web browser. It simulates the use of cookies and other HTTP specific components. 
    334  
    335 To change the environment in which you're browsing your application, just change the front controller. Until now, you have seen only the development environment, since the URLs used in the example called the development front controller
     327一个应用程序可以在不同的环境中运行。不同的环境共享相同的PHP代码(前端控制器除外),但是配置信息可能完全不同。symfony为每个应用程序提供三种默认的环境:生产(`prod`),测试(test),还有开发(dev)。只要你愿意你可以无限制的增加环境的数量。 
     328 
     329所以基本上,环境与配置是同义词。例如,测试环境会记录警告与错误,生产(`prod`)环境只记录错误。缓存加速功能在开发`dev`环境下通常是关闭的,但是在测试(`test`)与生产(`prod`)环境下开启。开发与测试环境所需要的测试数据,存放在与生产环境不同的数据库里。所以两种环境的数据库培植会有所不同。所有的环境可以在一台机器上共存,不过通常一台正式的服务器只包含生产`prod`环境。 
     330 
     331在开发环境下,日志与调试功能都是开启的,因为排除问题比性能更重要。相反,生产环境的配置默认是为性能优化的,所以生产环境会关闭一些功能。建议呆在开发环境直到你对开发的功能满意为止,然后切换到生产环境测试速度。 
     332 
     333测试环境又与开发与生产环境有所不同。你只能通过命令行来访问这个环境,通常是作功能测试与执行批处理脚本。因此,测试环境与生产环境接近,但是不能通过浏览器访问。它能模拟coookie与其它HTTP相关的组件。 
     334 
     335改变你正在访问的应用程序的环境,只要改变前端控制器就可以了。到目前为止,你只见过开发环境,因为例子里的URL都是开发环境前端控制器的
    336336 
    337337    http://localhost/myapp_dev.php/mymodule/index 
    338338 
    339 However, if you want to see how the application reacts in production, call the production front controller instead
     339不过,如果你想看看应用程序在生产环境中的样子,可以执行生产环境的前端控制器
    340340 
    341341    http://localhost/index.php/mymodule/index 
    342342 
    343 If your web server has mod_rewrite enabled, you can even use the custom symfony rewriting rules, written in `web/.htaccess`. They define the production front controller as the default execution script and allow for URLs like this
     343如果你的web服务器支持mod_rewrite,你甚至可以在`web/.htaccess`里自定symfony重写规则。这些规则把生产环境的前端控制器作为默认的执行脚本能让URL看上去像这样
    344344 
    345345    http://localhost/mymodule/index 
    346346 
    347347>**SIDEBAR** 
    348 >Environments and servers 
    349 > 
    350 >Don't mix up the notions of environment and server. In symfony, different environments are different configurations, and correspond to a front controller (the script that executes the request). Different servers correspond to different domain names in the URL. 
     348>环境与服务器 
     349> 
     350>不要把环境与服务器的概念混淆了。在symfon里,不同的环境是指不同的配置信息,对应不同的前端控制器(执行请求的脚本)。不同的服务器对应URL里的不同域名。 
    351351> 
    352352> 
    356356> 
    357357> 
    358 >Usually, developers work on applications in a development server, disconnected from the Internet and where all the server and PHP configuration can be changed at will. When the time comes for releasing the application to production, the application files are transferred to the production server and made accessible to the end users. 
    359 > 
    360 >This means that many environments are available on each server. For instance, you can run in the production environment even on your development server. However, most of the time, only the production environment should be accessible in the production server, to avoid public visibility of server configuration and security risks. 
    361 > 
    362 >To add a new environment, you don't need to create a directory or to use the symfony CLI. Simply create a new front controller and change the environment name definition in it. This environment inherits all the default configuration plus the settings that are common to all environments. The next chapter will show you how to do this. 
     358>通常,开发人员在一台开发服务器上工作,这台服务器不与互联网相同,所有的服务与PHP配置文件都可以自由修改。到了发布应用程序的时候,程序文件会传到生产服务器上然后最终用户才能访问得到。 
     359> 
     360>这意味着同一台服务器上可以有很多个环境。例如,你甚至可以在你的开发服务器上运行生产环境。不过,大多数时候,生产服务器上只能访问生产环境,这样可以避免服务器的配置信息泄露以减少安全方面的风险。 
     361> 
     362>定义一个新环境,不需要建立目录或者使用symfony命令行工具。只要建立一个新的前端控制器,修改这个前端控制器里面定义的环境名就可以了。这个环境会继承所有默认配置信息还有所有环境的共同配置信息。下一章会有详细介绍。 
    363363 
    364364### 配置层叠 Configuration Cascade 
    365365 
    366 The same setting can be defined more than once, in different places. For instance, you may want to set the mime-type of your pages to `text/html` for all of the application, except for the pages of an `rss` module, which will need a `text/xml` mime-type. Symfony gives you the ability to write the first setting in `myapp/config/view.yml` and the second in `myapp/modules/rss/config/view.yml`. The configuration system knows that a setting defined at the module level must override a setting defined at the application level. 
    367  
    368 In fact, there are several configuration levels in symfony
     366同样的配置信息可以在不同的地方定义多次。例如,你想把你的程序的所有页面的mime-type定义成`text/html`,只有一个`rss`模块例外,这个模块需要`text/xml`的mime-type。symfony可以让你在`myapp/config/view.yml`里面写第一个定义,然后再`myapp/modules/rss/config/view.yml`里面写第二个定义。配置系统了解模块级别的定义一定要覆盖应用程序级的定义。 
     367 
     368实际上,symfony的配置信息分成好几级
    369369 
    370370  * Granularity levels: