This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| protected function _editAction(Post $post) | |
| { | |
| $em = $this->get('doctrine.orm.default_entity_manager'); | |
| $factory = $this->get('form.factory'); | |
| $form = $factory->create(new PostFormType()); | |
| $form->setData($post); | |
| if ($this->get('request')->getMethod() === 'POST') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomRenderer extends \Symfony\Component\Form\Renderer\DefaultRenderer | |
| { | |
| public function getHelp($text, array $vars = array()) | |
| { | |
| $vars['text'] = $text; | |
| return $this->render('help', $vars); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form method="post" action="..." {{ form.enctype }}> | |
| {{ form.errors }} | |
| {% for field in form.visible_fields %} | |
| {{ field.label('My label') }} | |
| {{ field.errors }} | |
| {{ field.widget }} | |
| The ID of this field is: {{ field.id }} | |
| And the value: {{ field.value }} | |
| {% endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected function editAction(Post $post) | |
| { | |
| $factory = new HelloFormFactory($this->get('form.factory')); | |
| $form = $factory->getPostForm($post); | |
| if ($this->get('request')->getMethod() === 'POST') { | |
| $form->bindRequest($this->get('request')); | |
| if ($form->isValid()) { | |
| $em = $this->get('doctrine.orm.default_entity_manager'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Sensio\HelloBundle; | |
| use Symfony\Component\Form\FormFactory; | |
| use Sensio\HelloBundle\Entity\Post; | |
| use Sensio\HelloBundle\Entity\Comment; | |
| class HelloFormFactory | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git clone git://github.com/bschussek/symfony-sandbox.git | |
| cd symfony-sandbox | |
| git checkout -b hacking workshop-start | |
| cp app/config/doctrine.yml-dist app/config/doctrine.yml | |
| app/console doctrine:database:create | |
| app/console doctrine:schema:create | |
| app/console doctrine:data:load |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Using a static OptionSupport class that automatically writes options into properties AND fields extend it. | |
| + Options are set in the very beginning of the constructor | |
| + Concise | |
| + Error if option is not supported | |
| + Everything is a property, no special treatment of options | |
| + Good performance | |
| + Static options can be hidden from public access | |
| - Private properties wouldn't work, access not allowed from parent classes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| doctrine: | |
| dbal: | |
| dbname: xxxxxxxx | |
| user: xxxxxxxx | |
| password: ~ | |
| logging: %kernel.debug% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Services for a bundle are always loaded | |
| # hello configLoad() will be called automatically (if defined) | |
| # Namespaces can be simplified | |
| doctrine: | |
| dbal: | |
| dbname: xxxxxxxx | |
| user: xxxxxxxx | |
| password: ~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| The current way, using addOption(), addRequiredOption() and getOption() | |
| + Concise | |
| + Error if option is not supported | |
| - Slow, because the addOption() calls are executed for every new instance | |
| - Base class Configurable needed | |
| - Overriding options in parent fields very intransparent | |
| - Options need special treatment ($this->required vs. $this->getOption('required')) | |
| - Problems with accessing required options before parent::__construct() |