如何在 Magento 中获取模型对象实例的引用
我正在创建一个处理注册过程的模块,该模块需要用户支付一定数量的注册费。基本流程是1)用户在第一页输入个人信息,并将表单发布到第二页2)用户在包含PayPal按钮的第二页中查看信息。 3) 确认后,用户点击 PayPal 按钮,并重定向至 PayPal 付款页面 4) 如果交易完成,用户将被重定向到成功页面;如果交易未完成,用户将被重定向到取消页面。我创建了一个名为“registration”的表,其中包含注册的一般信息,例如 id、注册名称等。在“PostAction”函数(与第二页相关)中,我使用发布的信息设置模型属性表单,但不要调用我认为应该在 SuccesAction 中完成的 save() 方法(与成功页面相关)。我的问题是如何获取 SuccessAction 中模型对象的引用,以便我可以使用 save() 方法将其插入数据库。此外,欢迎任何改进模块的建议或想法。
I am creating a module dealing with a registration process which requires a certain amount of registration fee from its user. the basic flow is 1)user inputs personal information in the first page, and posts the form to the second page 2) user reviews the information in the second page which contains a PayPal button. 3) after confirmation, user clicks the PayPal button and is redirected the PayPal payment page 4) user is redirected to a success page if transaction is finished or to a cancel page if transaction not finished. I created a table called 'registration' that holds the general info for a registration such as id, register name and etc. In the 'PostAction' function (related to the second page), I set the model attributes by using info from the posted form, but do not call the save() method which I think should be done in the SuccesAction (related to success page). My question is how to get the reference to the model object in the SuccessAction so I can use the save() method to insert it into the database. Also, any suggestion or idea to improve the module is welcomed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦“postAction”页面完成,注册对象/模型就会被处理。除非它已保存在某个地方,否则您无法取回它。某个地方可能是会话变量,但这些变量可能会在您最意想不到的时候过期(请参阅Finagle 定律) 所以保存到数据库更好。一个单独的表或通过用状态标记注册来显示它尚未完成 - “successAction”将通过设置该标记然后再次保存来完成该过程。
作为一个例子,考虑订单如何通过结帐。直到客户到达最后一步并提交订单为止,它只是一个报价,并且到目前为止已保存在
sales_flat_quote
表中。之后,它会保存在sales_flat_order
中。The registration object/model is disposed as soon as the 'postAction' page completes. You cannot get it back unless it has been saved somewhere. That somewhere could be a session variable, but those can expire when you least expect it (see Finagle's Law) so saving to the database is better. Either a separate table or by marking the registration with a status to show it is not yet complete - the 'successAction' would complete the process by setting that marker then saving again.
As an example consider how orders pass through checkout. Until the customer gets to the last step and submits the order, it is only a quote and has been saved in the
sales_flat_quote
table so far. After that point it is saved insales_flat_order
instead.