8000 Unable to pass objects to {{ render }} when embedding a controller anymore · Issue #6822 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Unable to pass objects to {{ render }} when embedding a controller anymore #6822

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nail opened this issue Jan 21, 2013 · 8 comments
Closed

Comments

@nail
Copy link
nail commented Jan 21, 2013

Hello,

I'm not sure if this is a regression or if this is on purpose due to the changes made to fix CVE-2012-6432, but we can't seem to be able to pass objects to subrequests anymore, only scalars, after having updated to the latest sf 2.2.

For example, what used to be:

{% render "SomeBundle:Foo:Bar" with {'someObject': someObject} %}

Should now become:

{{ render(controller("SomeBundle:Foo:Bar", {'someObject': someObject}) }}

However if someObject is an instance of SomeObject, this will throw an exception saying that the action "...requires that you provide a value for the "$someObject" argument...". The action signature being public function widgetAction($someObject). When adding typehinting (widgetAction(SomeObject $someObject)), an "Unable to guess how to get a Doctrine instance from the request information." error is thrown (adding a ParamConverter doesn't help)

The ability to pass objects was quite handy, especially to avoid reloading entities based on their ids in re-usable widgets/partials. Has this feature been removed deliberately? (or maybe am I doing something wrong?)

@jakzal
Copy link
Contributor
jakzal commented Jan 23, 2013

At the moment it is possible with:

{% render url('some_foo_bar', {'someObject': someObject}) with {} %}

Than in the controller you can access your object with:

$request->query->get('someObject');

Of course it won't work with standalone rendering.

Similar issue: #6788

@nail
Copy link
Author
nail commented Jan 24, 2013

Thanks but unfortunately it doesn't help. It really seems to skip objects. (I just updated to sf 2.2 beta 2)

With the following:

{% render url('some_foo_bar', {'someObject': someObject, 'foo': 'bar'}) %}

foo is the only parameters available in $request->query

@fabpot
Copy link
Member
fabpot commented Feb 1, 2013

Can you confirm that #6942 fixes this issue?

@nail
Copy link
Author
nail commented Feb 4, 2013

Yes it does, thanks!

fabpot added a commit that referenced this issue Feb 4, 2013
This PR was merged into the 2.2 branch.

Commits
-------

8f8d6cf [HttpKernel] fixed regression when rendering an inline controller and passing some objects  (closes #6822)

Discussion
----------

[HttpKernel] fixed regression when rendering an inline controller and passing some objects (closes #6822)

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6822
| License       | MIT
| Doc PR        | n/a
@fabpot fabpot closed this as completed Feb 4, 2013
fabpot added a commit that referenced this issue Feb 4, 2013
* 2.2:
  fixed regression in the Finder component (it was possible to use it without using exec before, closes #6357)
  fixed a circular call (closes #6864)
  typo
  [Security] [Tests] added unit tests for the UserPasswordValidator class and made the validator service for the UserPassword constraint configurable.
  fixed wrong indentation
  tweaked previous commit
  [HttpKernel] Fix the URI signer (closes #6801)
  Add Arabic translations.
  [HttpKernel] fixed regression when rendering an inline controller and passing some objects  (closes #6822)
  [FrameworkBundle] fixed typo
  renamed some classes and Twig functions to more descriptive names (refs #6871)
  Classcollectionloader: fix traits + enhancements
  Fix a deprecated method call in the tests
  Update `composer.json` files: - to allow versions ~2.2 (>=2.2,<3.0) of Doctrine DBAL, ORM & Common - fixed Propel1 versions difference between main and bridge files - fixed Twig versions difference between main and bridge files - to allow versions ~1.11 (>=1.11,<2.0) of Twig - fixed Locale ext-intl version to accept all, not non-existing version
  Correct comment in NativeSessionStorage regarding session.save_handler
  [Security] Add PHPDoc to AuthenticationEvents
@khusseini
Copy link

Hi there,
I am using version 2.3.1 and I am encountering this issue only in the "prod" environment.

{% for box in pageparts %}
    {{ render_esi(controller(box.controller, { pagePart: box })) }}
{% endfor %}

In my dev environment everything renders well, however in production environment I get the error

[2014-03-24 16:01:55] request.CRITICAL: Uncaught PHP Exception RuntimeException: "Controller "Kunstmaan\PagePartBundle\Controller\PagePartController::indexAction()" requires that you provide a value for the "$pagePart" argument (because there is no default value or because there is a non optional argument after this one)." at /var/www2/cmsdemo/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php line 134 {"exception":"[object] (RuntimeException: Controller \"Kunstmaan\\PagePartBundle\\Controller\\PagePartController::indexAction()\" requires that you provide a value for the \"$pagePart\" argument (because there is no default value or because there is a non optional argument after this one). at /var/www2/cmsdemo/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php:134)"} {"user":{"username":"admin","roles":["ROLE_SUPER_ADMIN","ROLE_PERMISSIONMANAGER","ROLE_ADMIN","ROLE_USER"],"is_account_non_expired":true,"is_account_non_locked":true,"is_credentials_non_expired":true,"is_enabled":true},"file":"/var/www2/cmsdemo/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php","line":104,"class":"Symfony\\Component\\HttpKernel\\EventListener\\ExceptionListener","function":"logException"}

I also made sure that all caches are cleared and that the box variable actually holds an object.

@khusseini
Copy link

I just tried to use the render instead of render_esi and it worked

9C18
@cordoval
Copy link
Contributor

Please use the mailing list for that bundle.

@xabbuh
Copy link
Member
xabbuh commented Feb 18, 2016

The closing parenthesis is at the wrong position. Use this instead:

{{ render(controller('AppBundle:Default:buildNavigation', {
            'foo': 25,
            'bar': 50
})) }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
0