0

I'm working on a small marketing project with Zend Framework, the backoffice of the project is currently made of two controller: a campaign controller and a minisite controller. The user create a campaign with a form, then he have to create a minisite with a second form linked to this campaign, so i need to get the campaign and the user id when saving the data of the minisite.

What is the best practice and why? should i pass those variables in a session object? or should i pass those variables through a route like :

/backoffice/minisite/create/:userid/:campaign/

Edit: users are logged and authenticated when creating campaigns

DoesNotCompute
  • 131
  • 1
  • 10

4 Answers4

1

Assuming users have to be logged in to do this, you could store the user information you need in a Zend_Auth identity

If not, you could store the data in a normal session var with Zend_Session or redirect to with the route. Either option is good, so it's up to you to pick the one which best suits you and your application.

adlawson
  • 6,303
  • 1
  • 35
  • 46
1

For passinf information between two controller the best way is to use session to store the values globally . :-)

Justin Dominic
  • 1,227
  • 1
  • 10
  • 22
0

I would use the route option, as you suggest. Using sessions is going to end up being very difficult to test, debug, extend in the future etc.

ChrisA
  • 2,091
  • 1
  • 14
  • 23
  • Well, it would be just as easy/hard to extend using the route option. – markus Aug 25 '11 at 10:14
  • Yes, I guess once you actually understand it again it would probably be just as easy/hard. I was thinking in terms of when you come back in a year or so, it'll be much quicker to understand again, if its easy to see what is being passed around because it is there to see in the URLs. – ChrisA Aug 25 '11 at 10:23
  • Also, what would you do if you wanted to allow a user to create several campaigns, then create the minisites. Or maybe logout and login again before creating it. I'm thinking it would be much easier to have a link next to the campaign to go to the `minisite/create` action. – ChrisA Aug 25 '11 at 10:25
0

I'm pretty sure users need to have an account to do these things. If yes, there campaigns and minisites will be associated with them in some way. I'd store and retrieve these things from some form of database.

If you're not having authenticated users and you really just need to pass two variables to another action, use url parameters but be aware of the fact that users can mess with them and a lot of unexpected stuff can happen. Storing in the session is harder to manipulate in that way.

So, if no authentication is involved and the site is public, use the session, otherwise use neither but use storage.

markus
  • 40,136
  • 23
  • 97
  • 142
  • Good point, using routes seems to be a good solution but it would involve some extra work to check what the user is doing and then redirect it if he mess with the url parameters, like trying to edit other user's campaigns... – DoesNotCompute Aug 25 '11 at 11:05
  • i meant routes and extra database data – DoesNotCompute Aug 25 '11 at 11:13