根据Magento中的URL参数加载对象

根据Magento中的URL参数加载对象

本文介绍了根据Magento中的URL参数加载对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法为Magento商店创建自定义模块.

I am having trouble creating a custom module for my Magento store.

我已经成功添加了一条路线(/着陆点),并创建了/布局文件,这些文件在我的基本布局中显示了模板内容.我现在需要进一步说明这一点.

I have successfully added a route (/landing), and created/layout files that display template content within my base layout. I now need to move beyond that a bit.

我希望能够从URL加载参数,基于该参数获取一个对象,并根据对象的内容显示内容.

I want to be able to load a parameter from a URL, grab an object based on that parameter, and display things based on the contents of my object.

示例:用户浏览到domain.com/landing/cool/.这(希望)将调用着陆控制器.控制器将能够以某种方式拉出'cool'参数,并拉出与cool相关联的着陆物体.然后,我的模板可以获取该对象并显示其元素.

Example: User browsers to domain.com/landing/cool/. This (hopefully) would call the landing controller. Controller would somehow be able to pull the 'cool' parameter, and pull a landing object associated with cool. Then, my template can get that object and display its elements.

我知道那里有很多东西,但是我已经在这个问题上挣扎了好一阵子,却一无所获. Magento必须对其所有类别,项目等执行此操作.在那里有人知道我该怎么做吗?

I know there are a lot of bits there, but I have been cracking my head on this for a while and getting nowhere. Magento has to do this for all its categories, items, etc. Does anyone out there know how I can do it?

推荐答案

如果您执行domain.com/landing/[controller]/cool/[key]/[value],则可以执行$ this-> getRequest() -> getParam('[key]')以获取[value]的值.然后,您可以基于此设置模板,但是我认为这是一个不同的问题.让我知道您是否仍然感到困惑.

If you do domain.com/landing/[controller]/cool/[key]/[value], you can do $this->getRequest()->getParam('[key]') to get the value of [value]. You can then set the template based on that, but I think that's a different question. Let me know if you're still confused.

这篇关于根据Magento中的URL参数加载对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:59