Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove no longer necessary factory#2930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletionscookbook/form/dynamic_form_modification.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -270,11 +270,9 @@ and fill in the listener logic::
);
}

$factory = $builder->getFormFactory();

$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function(FormEvent $event) use($user, $factory){
function(FormEvent $event) use($user){
$form = $event->getForm();

$formOptions = array(
Expand All@@ -289,7 +287,7 @@ and fill in the listener logic::

// create the field, this is similar the $builder->add()
// field name, field type, data, options
$form->add($factory->createNamed('friend', 'entity',null,$formOptions));
$form->add('friend', 'entity', $formOptions);
}
);
}
Expand DownExpand Up@@ -372,16 +370,22 @@ it with :ref:`dic-tags-form-type`.
If you wish to create it from within a controller or any other service that has
access to the form factory, you then use::

class FriendMessageController extends Controller
use Symfony\Component\DependencyInjection\ContainerAware;

class FriendMessageController extends ContainerAware
{
public function newAction(Request $request)
{
$form = $this->createForm('acme_friend_message');
$form = $this->get('form.factory')->create('acme_friend_message');

// ...
}
}

If you extend the ``Symfony\Bundle\FrameworkBundle\Controller\Controller`` class, you can simply call::

$form = $this->createForm('acme_friend_message');

You can also easily embed the form type into another form::

// inside some other "form type" class
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp