【问题标题】:Get Product ID throught url in Custom page?通过自定义页面中的 url 获取产品 ID?
【发布时间】:2013-09-03 05:50:33
【问题描述】:

我遇到了无法解决的问题。部分原因是我无法用正确的术语来解释它。我是新手,很抱歉这个笨拙的问题。

您可以在下面看到我的目标概览。

我在我的 magento 中创建了一个自定义模块,它运行良好。

使用这个我创建了一个http://www.phparrow.com/magento/magento-create-a-simple-module/

在我的产品页面我有一个链接

<a href = "http://www.example.com/magenaresh/index.php/hello/ "> Click Here </a>

当我点击 Click Here 时,它会重定向到 http://www.example.com/magenaresh/index.php/hello/ 这个 URL 到这里一切正常...

但现在我想将 ProductID 与 URL 一起传递

为此我是这样写的

<?php 
    $product_id = $this->getProduct()->getId();
    echo $product_id;
?>

<a href = "http://www.example.com/magenaresh/index.php/hello/<?php echo $product_id ?> ">Click Here</a>

我再次点击Click Here它的显示

我在这里做错了吗?

有什么想法吗?

【问题讨论】:

  • 这是谁干的?删除你的评论更好
  • 我猜 config.xml 需要知道额外的参数?
  • 检查此链接可能对您有帮助 >> stackoverflow.com/questions/8469767/get-url-query-string
  • 这个问题似乎是题外话,因为它是关于使用第三方软件的支持请求,这里是 Magento。

标签: php javascript ajax magento module


【解决方案1】:

你可以在你的href中添加链接

<a href = "http://www.example.com/magenaresh/index.php/hello/index/index/product_id/<?php echo $product_id ?> ">Click Here</a>

并且在您的控制器中可以像以前一样访问 URL 参数;

$id = $this->getRequest()->get('product_id');

希望这对你有帮助。

【讨论】:

  • 是的..谢谢 :) 它为我工作&我如何在这里爆炸产品 ID
  • 你可以得到像 $productId = Mage::app()->getRequest()->getParam('product_id');让我知道它有用吗
  • 不,它不起作用..我想在 hello.phtml 中获取产品 ID
  • 请您投票支持我的答案,以便将来有人可以信任和使用。使用 get 和 set 方法获取您的产品价值参考 stackoverflow.com/questions/16270655/…stackoverflow.com/questions/4006183/…
【解决方案2】:

你好检查下面的代码

<a href = "http://www.example.com/magenaresh/index.php/hello/index/index/<?php echo $product_id ?> ">Click Here</a>

【讨论】:

    猜你喜欢
    • 2017-03-30
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多