php中通过$_GET方法检索值的问题

发布于 2024-08-03 23:22:03 字数 867 浏览 4 评论 0原文

我有一个链接,单击它后会调用一个函数。在该函数中,我设置 href 属性来传递 id 变量。如果我提醒 href 值,我会看到正确的 url 和 Id。但是在控制器中的相应函数中,如果我对该变量 Id 执行 $_GET,则不会获得该值。错误是什么?

这是我的链接:

<a href="http://localhost/FormBuilder/reports/export?height=220&width=350" id="export_entries" class="thickbox button" title= "Export" >Export</a>  

以及相应的单击功能:

$("#export_entries").click(function() {
    $(this).attr("href",$(this).attr("href")+"&id="+formid);
    alert($(this).attr("href"));
});

在这个警报框中,如果我单击第二个链接,我会得到如下值,

 http://localhost/FormBuilder/reports/export?height=220&width=350&id=2

但在控制器的导出函数中,我没有得到该值。变量 formid 为空。

function export()
   {

        $formid=$_GET['id'];
        echo " formid: ".$formid;
        $this->set('formid',$formid);
   }

I have a link and on clicking it, a function is called. In that function, I set the href attribute to pass an id variable. If I alert the href value, I see the correct url along with the Id. But in the corresponding function in the controller, If I do an $_GET of that variable Id, I do not get the value. What is the error?

This is my link:

<a href="http://localhost/FormBuilder/reports/export?height=220&width=350" id="export_entries" class="thickbox button" title= "Export" >Export</a>  

And the corresponding on click function:

$("#export_entries").click(function() {
    $(this).attr("href",$(this).attr("href")+"&id="+formid);
    alert($(this).attr("href"));
});

In this alert box,If I click the second link, I get the value as

 http://localhost/FormBuilder/reports/export?height=220&width=350&id=2

But In my export function in the controller I do not get the value. The variable formid is empty.

function export()
   {

        $formid=$_GET['id'];
        echo " formid: ".$formid;
        $this->set('formid',$formid);
   }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你的背包 2024-08-10 23:22:03

可能发生的情况是,您更改了 href 属性,但浏览器重定向到旧的未更改的 url,因为您正在处理锚元素的单击。

您可以使用 location 构建 url 字符串,附加参数并将用户直接重定向到该字符串.href

$("#export_entries").click(function(e) {
  location.href = $(this).attr("href")+"&id="+formid;
  e.preventDefault();
});

What is probably happening is that you change the href attribute, but the browser redirects to the old unchanged url, since you are handling the click of the anchor element.

You could build the url string, appending the parameter and redirect the user to it directly, using location.href:

$("#export_entries").click(function(e) {
  location.href = $(this).attr("href")+"&id="+formid;
  e.preventDefault();
});
笑看君怀她人 2024-08-10 23:22:03

在 CakePHP 中,参数的工作方式如下:

http://localhost/FormBuilder/reports/export/height:220/width:350/id:2

您可以使用来

http://localhost/FormBuilder/reports/export?height=220&width=350&id=2

检索控制器中的参数,

$formid = $this->params['id'];

它们被称为命名参数。进一步阅读:

http://book.cakephp.org/view/541/Named -参数

http://bakery.cakephp.org/articles/查看/传递命名参数

In CakePHP, parameters work like this:

http://localhost/FormBuilder/reports/export/height:220/width:350/id:2

instead of

http://localhost/FormBuilder/reports/export?height=220&width=350&id=2

You can retrieve the parameters in your controller with

$formid = $this->params['id'];

They are called named parameters. Further reading:

http://book.cakephp.org/view/541/Named-parameters

http://bakery.cakephp.org/articles/view/passing-named-parameters

拥抱没勇气 2024-08-10 23:22:03

我找到了解决问题的方法。即使我更改 JQuery 函数中的 href 属性,浏览器也会重定向到 CMS 所说的旧网址。但是,如果我提供 location.href,我的功能可以正常工作,但厚盒未加载。只有当我像我已经完成的那样在链接的 href 属性中设置新的 url 时,厚盒才会加载,即,

$(this).attr("href","http://localhost/FormBuilder/reports/export?height=220&width=350&id="+formid);

因此要动态更改 url,我按照 这个网站 我们不需要在链接本身中提及 href 属性。我们可以在点击链接后设置href属性,在链接的点击函数中添加

tb_open_new($(this).attr("href"));

设置href属性后的行,以在thickbox窗口中打开这个更改后的url。

I found a solution to my problem. Even if I change the href attribute in the JQuery function,the browser is redirected to the old url as said by CMS. But if I give location.href, I get the functionality working, but the thickbox isn't loaded. The thickbox gets loaded only if I set the new url in the href attribute of the link as I had already done, i.e.,

$(this).attr("href","http://localhost/FormBuilder/reports/export?height=220&width=350&id="+formid);

So to change the url dynamically, I went for changing the thickbox.js file as mentioned in this site where we need not mention the href attribute in the link itself. We could set the href attribute after clicking the link,in the click function of the link and add the line

tb_open_new($(this).attr("href"));

after setting the href attribute to open this changed url in the thickbox window..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文