Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Entity specified by string id in URL and multiple controllers using it
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Adam Chysky  
View profile  
 More options Jun 20 2012, 2:56 pm
From: Adam Chysky <a...@chysky.com>
Date: Wed, 20 Jun 2012 20:56:02 +0200
Local: Wed, Jun 20 2012 2:56 pm
Subject: Entity specified by string id in URL and multiple controllers using it
Hello,

I am almost complete symfony2 newbie, I tried to find simple solution
for my problem with no luck.

Imagine a database entity - Person for example. This Person should have
it's photogallery, simple blog, settings, etc.. Each of these sections
should be located in their separate controller classes
(PhotogalleryController, BlogController, etc..).

URLs are constructed like this:
http://www.homepage.com/[person_string_id]
http://www.homepage.com/[person_string_id]/photogallery
http://www.homepage.com/[person_string_id]/photogallery/new
http://www.homepage.com/[person_string_id]/blog
http://www.homepage.com/[person_string_id]/blog/new
http://www.homepage.com/[person_string_id]/settings
etc..

What (or where) is the best practice to read the Person entity from
database? I don't want to do it in every action in every controller but
all the actions with routes /[person_string_id]/**** need the Person entity.

I have read something about event listeners, I believe this could be
solution for me, but I could use some advice here.

Thanks

Adam


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Chysky  
View profile  
 More options Jun 20 2012, 3:56 pm
From: Adam Chysky <a...@chysky.com>
Date: Wed, 20 Jun 2012 21:56:01 +0200
Local: Wed, Jun 20 2012 3:56 pm
Subject: Entity specified by string id in URL and multiple controllers using it

Hello,

I am almost complete symfony2 newbie, I tried to find simple solution
for my problem with no luck.

Imagine a database entity - Person for example. This Person should have
it's photogallery, simple blog, settings, etc.. Each of these sections
should be located in their separate controller classes
(PhotogalleryController, BlogController, etc..).

URLs are constructed like this:
http://www.example.com/[person_string_id]
http://www.example.com/[person_string_id]/photogallery
http://www.example.com/[person_string_id]/photogallery/new
http://www.example.com/[person_string_id]/blog
http://www.example.com/[person_string_id]/blog/new
http://www.example.com/[person_string_id]/settings
etc..

What (or where) is the best practice to read the Person entity from
database? I don't want to do it in every action in every controller but
all the actions with routes /[person_string_id]/**** need the Person
entity.

I have read something about event listeners, I believe this could be
solution for me, but I could use some advice here.

Thanks

Adam


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luis...  
View profile  
 More options Jun 20 2012, 4:04 pm
From: "Luis..." <ltoap...@gmail.com>
Date: Wed, 20 Jun 2012 15:04:00 -0500
Subject: Re: [Symfony2] Entity specified by string id in URL and multiple controllers using it

Use ParamConverter

Luis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matteo G  
View profile  
 More options Jun 20 2012, 5:35 pm
From: Matteo G <matt...@gmail.com>
Date: Wed, 20 Jun 2012 14:35:04 -0700 (PDT)
Local: Wed, Jun 20 2012 5:35 pm
Subject: Re: Entity specified by string id in URL and multiple controllers using it

as itoapant suggests. There is a @*ParamConverter* directive for the route,
but you should name that param "id" like the property of the entity
http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/ann...

Another more basic way is to invoke your persistence layer (doctrine I
assume) and retrieve the entity

Something like (for doctrine orm)

$this->get('doctrine.orm.entity_manager')->getRepository('YourBundle:Person ')->findOneById($param);

If you don't want (and you shouldn't) rewrite this for every action just
create a method in the controller class, or even better, define a base
controller class and define all the methods there.

Il giorno mercoledì 20 giugno 2012 20:56:02 UTC+2, Adam Chysky ha scritto:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »