8000 Twig templates & Doctrine proxy object - symfony 2.2.0-RC2 · Issue #7122 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Twig templates & Doctrine proxy object - symfony 2.2.0-RC2 #7122

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
zd-dalibor opened this issue Feb 19, 2013 · 8 comments
Closed

Twig templates & Doctrine proxy object - symfony 2.2.0-RC2 #7122

zd-dalibor opened this issue Feb 19, 2013 · 8 comments

Comments

@zd-dalibor
Copy link

If you have for example "Item" entity with many to one relation between them and "Group" entity. In "Item" entity "group" parameter represents "Group" entity where it belongs with getter "getGroup" and setter "setGroup". "Group" consists "title" parameter with getter "getTitle" and setter "setTitle"

In controller for example you find one item with item id and pass that item to twig template as variable "item". In "item" object "group" parameter is now doctrine proxy object.

If you try to do this in twig template

{{ item.group.title }}

you will get this error

Twig_Error_Runtime: Item "title" for "Array" does not exist in "<some_twig_template>" at line <some_line>

Only parameter that twig can access in "item.group" object is "isInitialized".

@michelsalib
Copy link

Can you copy/paste your entities ? And also show us your controller that retrieve the item ?

@zd-dalibor
Copy link
Author

In previous example I tried to simplify things. This is the real entities.

User Entity: https://gist.github.com/dalibor983/4985875

CityDefinition Entity: https://gist.github.com/dalibor983/4985914

XML mappings for this two entities: https://gist.github.com/dalibor983/4985919

Controller code

$username = <some_username>;
$manager = $this->getDoctrine()->getManager();
$r = $manager->getRepository('<some_bundle>:User');
/* @var User $user */
$user = $r->findOneBy(array('loginUsername' => $username));
return $this->render('<some_twig>', array(
    'userData' => $user,
));

Twig consists

{{ userData.cityDefinition.longName }}

@stloyd
Copy link
Contributor
stloyd commented Feb 19, 2013

@dalibor983 Could you move this code to gist? It makes this issue really unreadable...

@zd-dalibor
Copy link
Author

The code above works in simfony 2.1 but not in 2.2.0RC2. I'm trying to upgrade from 2.1 to 2.2.0RC2

@zd-dalibor
Copy link
Author

I updated my post with gist links.

@zd-dalibor
Copy link
Author

I also use this in twig template:

{{ render(controller("<some_bundle>:Example:index", {"cityDef": userData.cityDefinition})) }}

and in "ExampleController:index" i have

public function indexAction($<
8000
/span>cityDef)
{
    $this->render(<some_twig>, array("cityDef" => $cityDef));
}

and in twig

{{ cityDef.longName }}

I also get error.

@zd-dalibor
Copy link
Author

I noticed that this twig call:

{{ render(controller("<some_bundle>:Example:index", {"cityDef": userData.cityDefinition})) }}

transformed "userData.cityDefinition" proxy object to array with one element "isInitialized => '1'" and
in "ExampleController:indexAction" I got this array for "$cityDef" parameter instead of proxy object.

@zd-dalibor
Copy link
Author

See issue #7124

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

3 participants
0