我正在使用 Zend Framework 开发一个小型营销项目,该项目的后台当前由两个控制器组成:一个活动控制器和一个小型站点控制器。
用户使用表单创建一个活动,然后他必须创建一个迷你网站,其中第二个表单链接到该活动,因此我需要在保存迷你网站的数据时获取活动和用户 ID。
最佳实践是什么?为什么?我应该在会话对象中传递这些变量吗?或者我应该通过以下路径传递这些变量:
/backoffice/minisite/create/:userid/:campaign/
编辑:创建活动时用户被记录并进行身份验证
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
发布评论
评论(4)
假设用户必须登录才能执行此操作,您可以将所需的用户信息存储在
Zend_Auth
身份如果没有,您可以使用
Zend_Session
或使用路由重定向到。任一选项都不错,因此您可以选择最适合您和您的应用程序的选项。Assuming users have to be logged in to do this, you could store the user information you need in a
Zend_Auth
identityIf 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.对于两个控制器之间的 passinf 信息,最好的方法是使用会话来全局存储值。 :-)
For passinf information between two controller the best way is to use session to store the values globally . :-)
我很确定用户需要有一个帐户才能执行这些操作。如果是,则活动和迷你网站将以某种方式与它们相关联。我会从某种形式的数据库中存储和检索这些东西。
如果您没有经过身份验证的用户,并且您实际上只需要将两个变量传递给另一个操作,请使用 url 参数,但要注意用户可能会干扰它们,并且可能会发生很多意想不到的事情。以这种方式存储在会话中更难操作。
因此,如果不涉及身份验证并且站点是公共的,请使用会话,否则不使用任何身份验证,而使用存储。
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.
正如您所建议的,我会使用路线选项。使用会话最终将变得非常难以测试、调试、将来扩展等。
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.