是否有一个 Magento 函数可以从此 url 获取“id”的值:
http://example.com/path/action/id/123
我知道我可以在“/”上拆分 url 以获取值,但我更喜欢单个函数。
这不起作用:
$id = $this->getRequest()->getParam('id');
是否有一个 Magento 函数可以从此 url 获取“id”的值:
http://example.com/path/action/id/123
我知道我可以在“/”上拆分 url 以获取值,但我更喜欢单个函数。
这不起作用:
$id = $this->getRequest()->getParam('id');
Magento 的默认路由算法使用三部分URL。
http://example.com/front-name/controller-name/action-method
所以当你打电话
http://example.com/path/action/id/123
这个词path
是你的名字,action
是你的控制器名,id
是你的动作方法。 这三个方法之后getParam
,就可以使用抓取键/值对了
http://example.com/path/action/id/foo/123
//in a controller
var_dump($this->getRequest()->getParam('foo'));
您也可以使用该getParams
方法获取参数数组
$this->getRequest()->getParams()
如果您的网址是以下结构:http://yoursiteurl.com/index.php/admin/sales_order_invoice/save/order_id/1795/key/b62f67bcaa908cdf54f0d4260d4fa847/
然后使用:
echo $this->getRequest()->getParam('order_id'); // output is 1795
如果您想获取所有 URL 值或参数值而不是使用下面的代码。
var_dump($this->getRequest()->getParams());
如果你的网址是这样的:http://magentoo.blogspot.com/magentooo/userId=21
然后使用它来获取 url 的值
echo $_GET['userId'];
如果您想了解有关此的更多信息,请单击此处。
如果它是 Magento 模块,则可以使用 Varien Object getter。如果是针对你自己的模块控制器,你可能需要使用 register 方法。
来源:http ://www.vjtemplates.com/blog/magento/register-and-registry