diff --git a/guides/Twig.rst b/guides/Twig.rst index b32fefba78e..9c8c7bfbe31 100644 --- a/guides/Twig.rst +++ b/guides/Twig.rst @@ -19,12 +19,12 @@ Enable the ``TwigBundle`` in your kernel:: public function registerBundles() { - $bundles = array( - // ... - new Symfony\Framework\TwigBundle\Bundle(), - ); + $bundles = array( + // ... + new Symfony\Framework\TwigBundle\Bundle(), + ); - // ... + // ... } Then, configure it: diff --git a/guides/doctrine/MongoDB.rst b/guides/doctrine/MongoDB.rst index 6e0cb986533..7e036bf9e20 100644 --- a/guides/doctrine/MongoDB.rst +++ b/guides/doctrine/MongoDB.rst @@ -31,10 +31,10 @@ you need to customize more you can specify the complete configuration: # config/config.yml doctrine_odm.mongodb: - server: mongodb://localhost:27017 - options: - connect: true - metadata_cache_driver: array # array, apc, xcache, memcache + server: mongodb://localhost:27017 + options: + connect: true + metadata_cache_driver: array # array, apc, xcache, memcache If you wish to use memcache to cache your metadata and you need to configure the ``Memcache`` instance you can do the following: @@ -42,15 +42,15 @@ If you wish to use memcache to cache your metadata and you need to configure the # config/config.yml doctrine_odm.mongodb: - server: mongodb://localhost:27017 - options: - connect: true - metadata_cache_driver: - type: memcache - class: Doctrine\Common\Cache\MemcacheCache - host: localhost - port: 11211 - instance_class: Memcache + server: mongodb://localhost:27017 + options: + connect: true + metadata_cache_driver: + type: memcache + class: Doctrine\Common\Cache\MemcacheCache + host: localhost + port: 11211 + instance_class: Memcache Multiple Connections ~~~~~~~~~~~~~~~~~~~~ @@ -60,24 +60,24 @@ If you need multiple connections and document managers you can use the following .. code-block:: yaml doctrine_odm.mongodb: - default_connection: conn2 - default_document_manager: dm2 - metadata_cache_driver: apc - connections: - conn1: - server: mongodb://localhost:27017 - options: - connect: true - conn2: - server: mongodb://localhost:27017 - options: - connect: true - document_managers: - dm1: - connection: conn1 - metadata_cache_driver: xcache - dm2: - connection: conn2 + default_connection: conn2 + default_document_manager: dm2 + metadata_cache_driver: apc + connections: + conn1: + server: mongodb://localhost:27017 + options: + connect: true + conn2: + server: mongodb://localhost:27017 + options: + connect: true + document_managers: + dm1: + connection: conn1 + metadata_cache_driver: xcache + dm2: + connection: conn2 Now you can retrieve the configured services connection services:: @@ -133,13 +133,11 @@ Multiple Connections: xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd http://www.symfony-project.org/schema/dic/doctrine/odm/mongodb http://www.symfony-project.org/schema/dic/doctrine/odm/mongodb/mongodb-1.0.xsd"> - + diff --git a/guides/doctrine/configuration.rst b/guides/doctrine/configuration.rst index 6c0927b7bcf..da14c1374de 100644 --- a/guides/doctrine/configuration.rst +++ b/guides/doctrine/configuration.rst @@ -37,18 +37,18 @@ the key named ``connections``: .. code-block:: yaml doctrine.dbal: - default_connection: default - connections: - default: - dbname: Symfony2 - user: root - password: null - host: localhost - customer: - dbname: customer - user: root - password: null - host: localhost + default_connection: default + connections: + default: + dbname: Symfony2 + user: root + password: null + host: localhost + customer: + dbname: customer + user: root + password: null + host: localhost If you have defined multiple connections you can use the ``getDatabaseConnection()`` as well but you must pass it an argument with the name of the connection you want to get:: @@ -67,13 +67,13 @@ ORM Configuration .. code-block:: yaml doctrine.orm: - default_entity_manager: default - cache_driver: apc # array, apc, memcache, xcache - entity_managers: - default: - connection: default - customer: - connection: customer + default_entity_manager: default + cache_driver: apc # array, apc, memcache, xcache + entity_managers: + default: + connection: default + customer: + connection: customer Just like the DBAL, if you have configured multiple ``EntityManager`` instances and want to get a specific one you can use the ``getEntityManager()`` method by just passing it an argument diff --git a/guides/emails.rst b/guides/emails.rst index 018ac01fede..793563201e3 100644 --- a/guides/emails.rst +++ b/guides/emails.rst @@ -13,12 +13,12 @@ Enable ``SwiftmailerBundle`` in your kernel:: public function registerBundles() { - $bundles = array( - // ... - new Symfony\Framework\SwiftmailerBundle\Bundle(), - ); + $bundles = array( + // ... + new Symfony\Framework\SwiftmailerBundle\Bundle(), + ); - // ... + // ... } Configuration diff --git a/guides/event/recipes.rst b/guides/event/recipes.rst index 139d7213a82..9bc3ab31baa 100644 --- a/guides/event/recipes.rst +++ b/guides/event/recipes.rst @@ -98,7 +98,7 @@ magic ``__call()`` method in the class you want to be extended like this:: // no listener was able to proces the event? The method does not exist if (!$event->isProcessed()) { - throw new \Exception(sprintf('Call to undefined method %s::%s.', get_class($this), $method)); + throw new \Exception(sprintf('Call to undefined method %s::%s.', get_class($this), $method)); } // return the listener returned value @@ -114,8 +114,8 @@ Then, create a class that will host the listener:: { // we only want to respond to the calls to the 'bar' method if ('bar' != $event['method']) { - // allow another listener to take care of this unknown method - return false; + // allow another listener to take care of this unknown method + return false; } // the subject object (the foo instance) diff --git a/guides/forms.rst b/guides/forms.rst index 787d0e981d3..300b035cd96 100644 --- a/guides/forms.rst +++ b/guides/forms.rst @@ -20,17 +20,19 @@ Let's see how this works in a practical example. Let's create a simple class Customer { - public $name; - - private $age = 20; - - public function getAge() { - return $this->age; - } - - public function setAge($age) { - $this->age = $age; - } + public $name; + + private $age = 20; + + public function getAge() + { + return $this->age; + } + + public function setAge($age) + { + $this->age = $age; + } } The class contains two properties ``name`` and "age". The property ``$name`` is @@ -41,13 +43,13 @@ Now let's create a form to let the visitor fill the data of the object:: // src/Application/HelloBundle/Controller/HelloController.php public function signupAction() { - $customer = new Customer(); - - $form = new Form('customer', $customer, $this->container->getValidatorService()); - $form->add(new TextField('name')); - $form->add(new IntegerField('age')); - - return $this->render('HelloBundle:Hello:signup', array('form' => $form)); + $customer = new Customer(); + + $form = new Form('customer', $customer, $this->container->getValidatorService()); + $form->add(new TextField('name')); + $form->add(new IntegerField('age')); + + return $this->render('HelloBundle:Hello:signup', array('form' => $form)); } A form consists of various fields. Each field represents a property in your @@ -61,9 +63,9 @@ simple template to render the form: extend('HelloBundle::layout') ?> renderFormTag('#') ?> - renderErrors() ?> - render() ?> - + renderErrors() ?> + render() ?> + When the user submits the form, we also need to handle the submitted data. @@ -72,22 +74,20 @@ All the data is stored in a POST parameter with the name of the form:: # src/Application/HelloBundle/Controller/HelloController.php public function signupAction() { - $customer = new Customer(); - $form = new Form('customer', $customer, $this->container->getValidatorService()); - - // form setup... - - if ($this->getRequest()->getMethod() == 'POST') - { - $form->bind($this->getRequest()->getParameter('customer')); + $customer = new Customer(); + $form = new Form('customer', $customer, $this->container->getValidatorService()); + + // form setup... + + if ($this->getRequest()->getMethod() == 'POST') { + $form->bind($this->getRequest()->getParameter('customer')); - if ($form->isValid()) - { - // save $customer object and redirect + if ($form->isValid()) { + // save $customer object and redirect + } } - } - - return $this->render('HelloBundle:Hello:signup', array('form' => $form)); + + return $this->render('HelloBundle:Hello:signup', array('form' => $form)); } Congratulations! You just created your first fully-functional form with @@ -154,8 +154,8 @@ whole objects or arrays. Let's add a new class ``Address`` to our model:: class Address { - public $street; - public $zipCode; + public $street; + public $zipCode; } Now we can add a property ``$address`` to the customer that stores one ``Address`` @@ -163,9 +163,9 @@ object:: class Customer { - // other properties ... - - public $address; + // other properties ... + + public $address; } We can use a field group to show fields for the customer and the nested address @@ -174,17 +174,17 @@ at the same time:: # src/Application/HelloBundle/Controller/HelloController.php public function signupAction() { - $customer = new Customer(); - $customer->address = new Address(); - - // form configuration ... - - $group = new FieldGroup('address'); - $group->add(new TextField('street')); - $group->add(new TextField('zipCode')); - $form->add($group); + $customer = new Customer(); + $customer->address = new Address(); + + // form configuration ... + + $group = new FieldGroup('address'); + $group->add(new TextField('street')); + $group->add(new TextField('zipCode')); + $form->add($group); - // process form ... + // process form ... } With only these little changes you can now edit also the ``Address`` object! @@ -210,9 +210,9 @@ will extend the ``Customer`` class to store three email addresses:: class Customer { - // other properties ... - - public $emails = array('', '', ''); + // other properties ... + + public $emails = array('', '', ''); } We will now add a ``CollectionField`` to manipulate these addresses:: @@ -246,16 +246,16 @@ Let's create a simple ``Registration`` class for this purpose:: class Registration { - /** @Validation({ @Valid }) */ - public $customer; - - /** @Validation({ @AssertTrue(message="Please accept the terms and conditions") }) */ - public $termsAccepted = false; - - public process() - { - // save user, send emails etc. - } + /** @Validation({ @Valid }) */ + public $customer; + + /** @Validation({ @AssertTrue(message="Please accept the terms and conditions") }) */ + public $termsAccepted = false; + + public process() + { + // save user, send emails etc. + } } Now we can easily adapt the form in the controller:: @@ -263,29 +263,27 @@ Now we can easily adapt the form in the controller:: # src/Application/HelloBundle/Controller/HelloController.php public function signupAction() { - $registration = new Registration(); - $registration->customer = new Customer(); - - $form = new Form('registration', $registration, $this->container->getValidatorService()); - $form->add(new CheckboxField('termsAccepted')); - - $group = new FieldGroup('customer'); - - // add customer fields to this group ... - - $form->add($group); - - if ($this->getRequest()->getMethod() == 'POST') - { - $form->bind($this->getRequest()->getParameter('customer')); - - if ($form->isValid()) - { - $registration->process(); + $registration = new Registration(); + $registration->customer = new Customer(); + + $form = new Form('registration', $registration, $this->container->getValidatorService()); + $form->add(new CheckboxField('termsAccepted')); + + $group = new FieldGroup('customer'); + + // add customer fields to this group ... + + $form->add($group); + + if ($this->getRequest()->getMethod() == 'POST') { + $form->bind($this->getRequest()->getParameter('customer')); + + if ($form->isValid()) { + $registration->process(); + } } - } - - return $this->render('HelloBundle:Hello:signup', array('form' => $form)); + + return $this->render('HelloBundle:Hello:signup', array('form' => $form)); } The big benefit of this refactoring is that we can reuse the ``Registration`` @@ -309,11 +307,11 @@ field:: # src/Application/HelloBundle/Resources/views/Hello/signup.php
- -
- renderErrors() ?> - render() ?> -
+ +
+ renderErrors() ?> + render() ?> +
You can access fields in field groups in the same way: @@ -329,13 +327,13 @@ for your hidden fields: .. code-block:: html+php - isHidden()): ?> - render() ?> - -
- ... -
- + isHidden()): ?> + render() ?> + +
+ ... +
+ By using plain HTML, you have the greatest possible flexibility in designing diff --git a/guides/testing/client.rst b/guides/testing/client.rst index 8d702a5f33c..76eb2104c88 100644 --- a/guides/testing/client.rst +++ b/guides/testing/client.rst @@ -35,8 +35,8 @@ and the form URL, it gives you a nice API to upload files, and it merges the submitted values with the form default ones, and more. .. tip:: - The Crawler is documented in its own :doc:`section `. Read it to learn more about - the ``Link`` and ``Form`` objects. + The Crawler is documented in its own :doc:`section `. Read it to + learn more about the ``Link`` and ``Form`` objects. But you can also simulate form submissions and complex requests with the additional arguments of the ``request()`` method:: diff --git a/guides/testing/crawler.rst b/guides/testing/crawler.rst index e2a87c64ecc..3a6b929ccf1 100644 --- a/guides/testing/crawler.rst +++ b/guides/testing/crawler.rst @@ -70,11 +70,11 @@ each method returns a new Crawler instance for the matching nodes:: $crawler ->filter('h1') ->reduce(function ($node, $i) - { - if (!$node->getAttribute('class')) { - return false; - } - }) + { + if (!$node->getAttribute('class')) { + return false; + } + }) ->first(); .. tip:: @@ -97,9 +97,9 @@ The Crawler can extract information from the nodes:: // Executes a lambda for each node and return an array of results $data = $crawler->each(function ($node, $i) - { - return $node->getAttribute('href'); - }); + { + return $node->getAttribute('href'); + }); Links ----- diff --git a/guides/tools/YAML.rst b/guides/tools/YAML.rst index 8abe3d8bbab..9b05e363ad2 100644 --- a/guides/tools/YAML.rst +++ b/guides/tools/YAML.rst @@ -35,10 +35,10 @@ the error type and the line in the original YAML string where the error occurred:: try { - $value = $yaml->parse(file_get_contents('/path/to/file.yaml')); + $value = $yaml->parse(file_get_contents('/path/to/file.yaml')); } catch (\InvalidArgumentException $e) { - // an error occurred during parsing - echo "Unable to parse the YAML string: ".$e->getMessage(); + // an error occurred during parsing + echo "Unable to parse the YAML string: ".$e->getMessage(); } .. tip:: @@ -110,8 +110,8 @@ the output switches from the expanded representation to the inline one:: foo: bar bar: - foo: bar - bar: baz + foo: bar + bar: baz The YAML Syntax --------------- @@ -275,23 +275,23 @@ YAML uses indentation with one or more spaces to describe nested collections: .. code-block:: yaml "symfony 1.4": - PHP: 5.2 - Doctrine: 1.2 + PHP: 5.2 + Doctrine: 1.2 "Symfony2": - PHP: 5.3 - Doctrine: 2.0 + PHP: 5.3 + Doctrine: 2.0 The following YAML is equivalent to the following PHP code:: array( - 'symfony 1.4' => array( - 'PHP' => 5.2, - 'Doctrine' => 1.2, - ), - 'Symfony2' => array( - 'PHP' => 5.3, - 'Doctrine' => 2.0, - ), + 'symfony 1.4' => array( + 'PHP' => 5.2, + 'Doctrine' => 1.2, + ), + 'Symfony2' => array( + 'PHP' => 5.3, + 'Doctrine' => 2.0, + ), ); There is one important thing you need to remember when using indentation in a @@ -303,11 +303,11 @@ You can nest sequences and mappings as you like: .. code-block:: yaml 'Chapter 1': - - Introduction - - Event Types + - Introduction + - Event Types 'Chapter 2': - - Introduction - - Helpers + - Introduction + - Helpers YAML can also use flow styles for collections, using explicit indicators rather than indentation to denote scope. @@ -359,9 +359,9 @@ In Symfony, a YAML file can contain PHP code that is evaluated just before the parsing occurs:: 1.0: - version: + version: 1.1: - version: "" + version: "" Be careful to not mess up with the indentation. Keep in mind the following simple tips when adding PHP code to a YAML file: diff --git a/guides/tools/autoloader.rst b/guides/tools/autoloader.rst index a1c40acaea0..1fbfbd582d9 100644 --- a/guides/tools/autoloader.rst +++ b/guides/tools/autoloader.rst @@ -42,8 +42,8 @@ If the classes to autoload use namespaces, use the ``registerNamespace()`` or $loader->registerNamespace('Symfony', __DIR__.'/vendor/symfony/src'); $loader->registerNamespaces(array( - 'Symfony' => __DIR__.'/vendor/symfony/src', - 'Zend' => __DIR__.'/vendor/zend/library', + 'Symfony' => __DIR__.'/vendor/symfony/src', + 'Zend' => __DIR__.'/vendor/zend/library', )); For classes that follow the PEAR naming convention, use the ``registerPrefix`` @@ -52,8 +52,8 @@ or ``registerPrefixes`` methods:: $loader->registerPrefix('Twig_', __DIR__.'/vendor/twig/lib'); $loader->registerPrefixes(array( - 'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes', - 'Twig_' => __DIR__.'/vendor/twig/lib', + 'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes', + 'Twig_' => __DIR__.'/vendor/twig/lib', )); .. note:: @@ -65,10 +65,10 @@ for in a list of locations to ease the vendoring of a sub-set of classes for large projects:: $loader->registerNamespaces(array( - 'Doctrine\Common' => __DIR__.'/vendor/doctrine/lib/vendor/doctrine-common/lib', - 'Doctrine\DBAL\Migrations' => __DIR__.'/vendor/doctrine-migrations/lib', - 'Doctrine\DBAL' => __DIR__.'/vendor/doctrine/lib/vendor/doctrine-dbal/lib', - 'Doctrine' => __DIR__.'/vendor/doctrine/lib', + 'Doctrine\Common' => __DIR__.'/vendor/doctrine/lib/vendor/doctrine-common/lib', + 'Doctrine\DBAL\Migrations' => __DIR__.'/vendor/doctrine-migrations/lib', + 'Doctrine\DBAL' => __DIR__.'/vendor/doctrine/lib/vendor/doctrine-dbal/lib', + 'Doctrine' => __DIR__.'/vendor/doctrine/lib', )); In this example, if you try to use a class in the ``Doctrine\Common`` namespace diff --git a/guides/tools/finder.rst b/guides/tools/finder.rst index 7d8c4b2d820..2a66e223643 100644 --- a/guides/tools/finder.rst +++ b/guides/tools/finder.rst @@ -176,10 +176,9 @@ To restrict the matching file with your own strategy, use ``filter()``:: $filter = function (\SplFileInfo $file) { - if (strlen($file) > 10) - { - return false; - } + if (strlen($file) > 10) { + return false; + } }; $finder->files()->filter($filter); diff --git a/guides/validator.rst b/guides/validator.rst index 5ce63091802..0f92d0a1c24 100644 --- a/guides/validator.rst +++ b/guides/validator.rst @@ -18,23 +18,23 @@ methods prefixed with "get" or "is". Let's look at a sample configuration:: class Author { - /** - * @Validation({ - * @NotBlank, - * @MinLength(4) - * }) - */ - public $firstName; + /** + * @Validation({ + * @NotBlank, + * @MinLength(4) + * }) + */ + public $firstName; - /** - * @Validation({ - * @Email(message="Ok, seriously now. Your email address please") - * }) - */ - public function getEmail() - { - return 'foobar'; - } + /** + * @Validation({ + * @Email(message="Ok, seriously now. Your email address please") + * }) + */ + public function getEmail() + { + return 'foobar'; + } } This snippet shows a very simple ``Author`` class with a property and a getter. @@ -49,7 +49,7 @@ by default. You can enable it in your ``config.yml``: # hello/config/config.yml web.validation: - annotations: true + annotations: true Now let's try to validate an object:: @@ -63,9 +63,9 @@ Now let's try to validate an object:: You should see the following output:: Author.firstName: - This value is too short. It should have 4 characters or more + This value is too short. It should have 4 characters or more Author.email: - Ok, seriously now. Your email address please + Ok, seriously now. Your email address please The ``validate()`` method returns a ``ConstraintViolationList`` object that can simply be printed or processed in your code. That was easy! @@ -368,17 +368,17 @@ validated to prevent errors. To use the driver, simply put a file called xsi:schemaLocation="http://www.symfony-project.org/schema/dic/constraint-mapping http://www.symfony-project.org/schema/dic/services/constraint-mapping-1.0.xsd"> - - - - 4 - - - - - - - + + + + 4 + + + + + + + YAML Configuration @@ -391,14 +391,14 @@ bundle: .. code-block:: yaml Application\HelloBundle\Model\Author: - properties: - firstName: - - NotBlank: ~ - - MinLength: 4 + properties: + firstName: + - NotBlank: ~ + - MinLength: 4 - getters: - email: - - Email: { message: "Ok, seriously now. Your email address please" } + getters: + email: + - Email: { message: "Ok, seriously now. Your email address please" } PHP Configuration ~~~~~~~~~~~~~~~~~ @@ -411,14 +411,14 @@ method ``loadValidatorMetadata()`` to the classes that you want to validate:: class Author { - public static function loadValidatorMetadata(ClassMetadata $metadata) - { - $metadata->addPropertyConstraint('firstName', new Constraints\NotBlank()); - $metadata->addPropertyConstraint('firstName', new Constraints\MinLength(3)); - $metadata->addGetterConstraint('email', new Constraints\Email(array( - 'message' => 'Ok, seriously now. Your email address please', - ))); - } + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('firstName', new Constraints\NotBlank()); + $metadata->addPropertyConstraint('firstName', new Constraints\MinLength(3)); + $metadata->addGetterConstraint('email', new Constraints\Email(array( + 'message' => 'Ok, seriously now. Your email address please', + ))); + } } You can use either of the configuration drivers, or all together. Symfony will diff --git a/quick_tour/the_big_picture.rst b/quick_tour/the_big_picture.rst index 5e5a926dc0c..958b96f4f57 100644 --- a/quick_tour/the_big_picture.rst +++ b/quick_tour/the_big_picture.rst @@ -28,19 +28,19 @@ Download the `sandbox`_, and unpack it in your root web directory. You should now have a ``sandbox/`` directory:: www/ <- your web root directory - sandbox/ <- the unpacked archive - hello/ - cache/ - config/ - logs/ - src/ - Application/ - HelloBundle/ - Controller/ - Resources/ - vendor/ - symfony/ - web/ + sandbox/ <- the unpacked archive + hello/ + cache/ + config/ + logs/ + src/ + Application/ + HelloBundle/ + Controller/ + Resources/ + vendor/ + symfony/ + web/ .. index:: single: Installation; Check pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy