diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 278f7c2c39c..00000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,7 +0,0 @@ -Contributing ------------- - -We love contributors! For more information on how you can contribute to the -Symfony documentation, please read [Contributing to the Documentation](http://symfony.com/doc/current/contributing/documentation/overview.html) -and notice the [Pull Request Format](http://symfony.com/doc/current/contributing/documentation/overview.html#pull-request-format) -that helps us merge your pull requests faster! diff --git a/README.markdown b/README.markdown index afa5925f03f..935b8ce5f10 100644 --- a/README.markdown +++ b/README.markdown @@ -1,16 +1,16 @@ -Symfony Documentation -===================== +Symfony中文文档 +=============== -This documentation is rendered online at http://symfony.com/doc/current/ +翻译中 / In progress -Contributing ------------- +请针对2.0分支进行翻译! ->**Note** ->Unless you're documenting a feature that's new to a specific version of Symfony ->(e.g. Symfony 2.1), all pull requests must be based off of the **2.0** branch, ->**not** the master or 2.1 branch. +如果你使用命令行的Git,在复制(clone)文档源代码后,可用以下命令检出(checkout)2.0分支: -We love contributors! For more information on how you can contribute to the -Symfony documentation, please read -[Contributing to the Documentation](http://symfony.com/doc/current/contributing/documentation/overview.html) + git checkout 2.0 + +可以用以下命令确认是否当前工作分支是2.0分支: + + git status + +[在线版本](http://symfony.cn/docs) diff --git a/book/_security-2012-6431.rst.inc b/book/_security-2012-6431.rst.inc deleted file mode 100644 index 5d9137bba63..00000000000 --- a/book/_security-2012-6431.rst.inc +++ /dev/null @@ -1,9 +0,0 @@ -.. note:: - - Since Symfony 2.0.20/2.1.5, the Twig ``render`` tag now takes an absolute url - instead of a controller logical path. This fixes an important security - issue (`CVE-2012-6431`_) reported on the official blog. If your application - uses an older version of Symfony or still uses the previous ``render`` tag - syntax, you should upgrade as soon as possible. - -.. _`CVE-2012-6431`: http://symfony.com/blog/security-release-symfony-2-0-20-and-2-1-5-released \ No newline at end of file diff --git a/book/controller.rst b/book/controller.rst index 5bcdd2d1fc0..ba82c671f09 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -11,7 +11,7 @@ a serialized JSON array, an image, a redirect, a 404 error or anything else you can dream up. The controller contains whatever arbitrary logic *your application* needs to render the content of a page. -See how simple this is by looking at a Symfony2 controller in action. +To see how simple this is, let's look at a Symfony2 controller in action. The following controller would render a page that simply prints ``Hello world!``:: use Symfony\Component\HttpFoundation\Response; @@ -73,7 +73,7 @@ maps a URL to that controller (#2). .. note:: Though similarly named, a "front controller" is different from the - "controllers" talked about in this chapter. A front controller + "controllers" we'll talk about in this chapter. A front controller is a short PHP file that lives in your web directory and through which all requests are directed. A typical application will have a production front controller (e.g. ``app.php``) and a development front controller @@ -94,15 +94,15 @@ a controller object. Controllers are also called *actions*. :linenos: // src/Acme/HelloBundle/Controller/HelloController.php - namespace Acme\HelloBundle\Controller; + namespace Acme\HelloBundle\Controller; use Symfony\Component\HttpFoundation\Response; class HelloController { public function indexAction($name) { - return new Response('
Hello '.$name.'!'); + return new Response('Hello '.$name.'!'); } } @@ -115,11 +115,11 @@ a controller object. Controllers are also called *actions*. will house several controllers/actions (e.g. ``updateAction``, ``deleteAction``, etc). -This controller is pretty straightforward: +This controller is pretty straightforward, but let's walk through it: -* *line 4*: Symfony2 takes advantage of PHP 5.3 namespace functionality to +* *line 3*: Symfony2 takes advantage of PHP 5.3 namespace functionality to namespace the entire controller class. The ``use`` keyword imports the - ``Response`` class, which the controller must return. + ``Response`` class, which our controller must return. * *line 6*: The class name is the concatenation of a name for the controller class (i.e. ``Hello``) and the word ``Controller``. This is a convention @@ -202,11 +202,14 @@ Route Parameters as Controller Arguments You already know that the ``_controller`` parameter ``AcmeHelloBundle:Hello:index`` refers to a ``HelloController::indexAction()`` method that lives inside the ``AcmeHelloBundle`` bundle. What's more interesting is the arguments that are -passed to that method:: +passed to that method: +.. code-block:: php + + createForm(...); - + $form->bindRequest($request); // ... } @@ -332,14 +335,6 @@ working with forms, for example:: .. index:: single: Controller; Base controller class -Creating Static Pages ---------------------- - -You can create a static page without even creating a controller (only a route -and template are needed). - -Use it! See :doc:`/cookbook/templating/render_without_controller`. - The Base Controller Class ------------------------- @@ -349,11 +344,13 @@ access to any resource it might need. By extending this ``Controller`` class, you can take advantage of several helper methods. Add the ``use`` statement atop the ``Controller`` class and then modify the -``HelloController`` to extend it:: +``HelloController`` to extend it: + +.. code-block:: php // src/Acme/HelloBundle/Controller/HelloController.php - namespace Acme\HelloBundle\Controller; + namespace Acme\HelloBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; @@ -361,7 +358,7 @@ Add the ``use`` statement atop the ``Controller`` class and then modify the { public function indexAction($name) { - return new Response('Hello '.$name.'!'); + return new Response('Hello '.$name.'!'); } } @@ -378,15 +375,16 @@ itself. Extending the base class is *optional* in Symfony; it contains useful shortcuts but nothing mandatory. You can also extend - :class:`Symfony\\Component\\DependencyInjection\\ContainerAware`. The service + ``Symfony\Component\DependencyInjection\ContainerAware``. The service container object will then be accessible via the ``container`` property. .. note:: - You can also define your :doc:`Controllers as Services`. + You can also define your :doc:`Controllers as Services + `. .. index:: - single: Controller; Common tasks + single: Controller; Common Tasks Common Controller Tasks ----------------------- @@ -424,7 +422,9 @@ perform a 301 (permanent) redirect, modify the second argument:: .. tip:: The ``redirect()`` method is simply a shortcut that creates a ``Response`` - object that specializes in redirecting the user. It's equivalent to:: + object that specializes in redirecting the user. It's equivalent to: + + .. code-block:: php use Symfony\Component\HttpFoundation\RedirectResponse; @@ -445,11 +445,11 @@ object that's returned from that controller:: { $response = $this->forward('AcmeHelloBundle:Hello:fancy', array( 'name' => $name, - 'color' => 'green', + 'color' => 'green' )); - // ... further modify the response or return it directly - + // further modify the response or return it directly + return $response; } @@ -478,15 +478,12 @@ value to each variable. a shortcut for core Symfony2 functionality. A forward can be accomplished directly via the ``http_kernel`` service. A forward returns a ``Response`` object:: - + $httpKernel = $this->container->get('http_kernel'); - $response = $httpKernel->forward( - 'AcmeHelloBundle:Hello:fancy', - array( - 'name' => $name, - 'color' => 'green', - ) - ); + $response = $httpKernel->forward('AcmeHelloBundle:Hello:fancy', array( + 'name' => $name, + 'color' => 'green', + )); .. index:: single: Controller; Rendering templates @@ -501,22 +498,14 @@ that's responsible for generating the HTML (or other format) for the controller. The ``renderView()`` method renders a template and returns its content. The content from the template can be used to create a ``Response`` object:: - use Symfony\Component\HttpFoundation\Response; - - $content = $this->renderView( - 'AcmeHelloBundle:Hello:index.html.twig', - array('name' => $name) - ); + $content = $this->renderView('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name)); return new Response($content); This can even be done in just one step with the ``render()`` method, which returns a ``Response`` object containing the content from the template:: - return $this->render( - 'AcmeHelloBundle:Hello:index.html.twig', - array('name' => $name) - ); + return $this->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name)); In both cases, the ``Resources/views/Hello/index.html.twig`` template inside the ``AcmeHelloBundle`` will be rendered. @@ -524,22 +513,13 @@ the ``AcmeHelloBundle`` will be rendered. The Symfony templating engine is explained in great detail in the :doc:`Templating ` chapter. -.. tip:: - - You can even avoid calling the ``render`` method by using the ``@Template`` - annotation. See the FrameworkExtraBundle - more details. - .. tip:: The ``renderView`` method is a shortcut to direct use of the ``templating`` service. The ``templating`` service can also be used directly:: - + $templating = $this->get('templating'); - $content = $templating->render( - 'AcmeHelloBundle:Hello:index.html.twig', - array('name' => $name) - ); + $content = $templating->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name)); .. note:: @@ -547,10 +527,7 @@ The Symfony templating engine is explained in great detail in the be careful to avoid the pitfall of making your directory structure unduly elaborate:: - $templating->render( - 'AcmeHelloBundle:Hello/Greetings:index.html.twig', - array('name' => $name) - ); + $templating->render('AcmeHelloBundle:Hello/Greetings:index.html.twig', array('name' => $name)); // index.html.twig found in Resources/views/Hello/Greetings is rendered. .. index:: @@ -576,7 +553,7 @@ command: .. code-block:: bash - $ php app/console container:debug + php app/console container:debug For more information, see the :doc:`/book/service_container` chapter. @@ -593,8 +570,7 @@ If you're extending the base controller class, do the following:: public function indexAction() { - // retrieve the object from database - $product = ...; + $product = // retrieve the object from database if (!$product) { throw $this->createNotFoundException('The product does not exist'); } @@ -647,7 +623,7 @@ These attributes will remain on the user for the remainder of that user's session. .. index:: - single: Session; Flash messages + single Session; Flash messages Flash Messages ~~~~~~~~~~~~~~ @@ -667,10 +643,7 @@ For example, imagine you're processing a form submit:: if ($form->isValid()) { // do some sort of processing - $this->get('session')->setFlash( - 'notice', - 'Your changes were saved!' - ); + $this->get('session')->setFlash('notice', 'Your changes were saved!'); return $this->redirect($this->generateUrl(...)); } @@ -695,8 +668,8 @@ the ``notice`` message: {% endif %} - .. code-block:: html+php - + .. code-block:: php + hasFlash('notice')): ?>