GVKun编程网logo

php – URL中的多个GET同时?(php内嵌一个url)

14

本篇文章给大家谈谈php–URL中的多个GET同时?,以及php内嵌一个url的知识点,同时本文还将给你拓展.NETWebAPI中的多个URL级别、CakePHP:防止URL中的GET表单字段、js提

本篇文章给大家谈谈php – URL中的多个GET同时?,以及php内嵌一个url的知识点,同时本文还将给你拓展.NET Web API中的多个URL级别、CakePHP:防止URL中的GET表单字段、js提取URL中的各个GET参数,返回一个json、Magento去除URL中的index.php等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

php – URL中的多个GET同时?(php内嵌一个url)

php – URL中的多个GET同时?(php内嵌一个url)

我正在尝试从URL中获取变量,但每次URL已经有查询时,它都会被下一个查询覆盖.例:
我有一个链接;
<a href="?page=34">Page 34</a>

当您单击该链接时,此链接将变为可见;

<a href="?item=45">Item 45</a>

但是,当我点击该链接时,另一个被覆盖,因此URL看起来像;

www.domainname.ext/?item45

但我希望它看起来像;

www.domainname.ext/?page=34&item45

有办法吗?
提前致谢!

在给定的“页面”内,您需要存储页面ID并在创建“项目”链接时使用该存储的值.
<?PHP
$pageID = $_GET['page'];

// ....

?>

<a href="?page=<?PHP echo $pageID; ?>&amp;item=45" title="Item 45">Item 45</a>

.NET Web API中的多个URL级别

.NET Web API中的多个URL级别

我正在使用新的.NET Web API设置休息服务,我遇到了一个小问题.我们希望有一个不同的路由,但我不知道如何实现这一点.
public class FormController : ApiController
{

    // api/form
    public string Get()
    {
        return "OK-Get";
    }
    // api/form/method1
    public string Method1()
    {
        return "OK1";
    }
    // api/form/method2
    public string Method2()
    {
        return "OK2";
    }
}

但这不起作用.如果我转到/ api / form / method2,我会得到OK-Get作为回复.

我认为这与路由有关,但我不确定,因为我之前没有使用过MVC.我已经尝试在WebApiConfig.cs中设置它:

config.Routes.MapHttpRoute(
    name: "FormApi",routeTemplate: "api/form/{action}"
);

但那没有做任何事.

解决方法

路由几乎是正确的但主要问题是您在其他操作方法上缺少必需的HttpMethod属性. [HttpGet]是因为它的名字而在第一种方法上推断出来的.这就是你需要的:
public class FormController : ApiController
{
    // api/form
    public string Get()
    {
        return "OK-Get";
    }

    // api/form/method1
    [HttpGet]
    public string Method1()
    {
        return "OK1";
    }

    // api/form/method2
    [HttpGet]
    public string Method2()
    {
        return "OK2";
    }
}

使用属于App_Start / RouteConfig.cs的路由映射

routes.MapHttpRoute(
    name: "FormApi",routeTemplate: "api/form/{action}",defaults: new { controller = "form",action = "Get"}
);

有关更多信息,请阅读http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection

CakePHP:防止URL中的GET表单字段

CakePHP:防止URL中的GET表单字段

我有一个CakePHP搜索表单,其中包含“类型” =>“获取”.基本上,表单中的元素之一是图像类型的提交按钮.发布表单后,我总是在URL中得到这些x&图片提交按钮的y坐标:

http://site.com/controller/action?x = 22& y = 36& query = hello

有什么办法可以防止坐标显示在URL中?原因是其他人可以使用相同的URL来执行相同的搜索,而无需在链接中添加一些不直观的内容.

谢谢!

解决方法:

您可以在按钮上使用一些javascript:

document.getElementById('myImageButton').onclick = function() {
    this.form.submit();
    return false;
};

另外,在控制器中的beforeFilter函数中,您可以检查是否存在不需要的变量,将其删除,然后重定向到漂亮的URL.这确实意味着将有2个HTTP请求.

js提取URL中的各个GET参数,返回一个json

js提取URL中的各个GET参数,返回一个json

<table><tr>
<td><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

一个URL:http://item.taobao.com/item.htm?a=1&b=2&c=&d=xxx&e, 提取URL中的各个DET参数(参数名和参数个数不确定), 一个json结构中,如{a: "1",b: "2",c: "",d: "xxx",e: undefined}       getJsonurl         str url.         arr str.         json         i iarr.i             newarr             .arri                 newarr arri.                             newarr arri.                         jsonnewarr newarr                 json         url     console.  getJsonurl 输出{a: "3",e: undefined}   getDataurl     result     temp url..     i temp         s tempi.);         result[s[0]] = s[1];     }     return result; }     var url ="http://item.taobao.com/item.htm?a=1&a=3&b=2&c=&d=xxx&e";     console.log(  getData(url)); // 输出{a: "3",e: undefined}   // 方案三:遇到相同的key, value合并到一个数组中       function getJson(url) {         var str = url.split("?")[1],             arr = str.split("&"),             aj = [],             json = {};         function arrjson(item,i) {             aj[i] = item.split(" ='<="" span="">             key aji                 val aji             key json                 jsonkey jsonaji..val                             jsonkey val                                     arr.arrjson         json                 url     console.  getJsonurl   输出 {a: ["1","3"],e: undefined}

总结

以上是小编为你收集整理的js提取URL中的各个GET参数,返回一个json全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

Magento去除URL中的index.php

Magento去除URL中的index.php

Magento去掉URL中的index.php
1.修改APACHE2中的配置文件。

DocumentRoot /home/magento/ <directory></directory>  Options FollowSymLinks  AllowOverride  All   这里修改成All <directory></directory>  Options Indexes FollowSymLinks MultiViews  AllowOverride All    这里修改成All  Order allow,deny  allow from all 
登录后复制


2.启用apache2重写模块。
命令:#a2enmod rewrite

3.登录Magento后台系统,系统(System) => 配置(Configuration) => 网站(Web)=> 搜索引擎优化(Search Engines Optimization)=> 服务器重写(Use Web Server Rewrites),然后选择” yes” 即可(记得刷新Magento缓存).

4.修改.htaccess文件的配置

确保为:

############################################
## enable rewrites

    Options +FollowSymLinks
    RewriteEngine on

############################################
## you can put here your magento root folder
## path relative to web root

    RewriteBase /

/etc/in

今天关于php – URL中的多个GET同时?php内嵌一个url的讲解已经结束,谢谢您的阅读,如果想了解更多关于.NET Web API中的多个URL级别、CakePHP:防止URL中的GET表单字段、js提取URL中的各个GET参数,返回一个json、Magento去除URL中的index.php的相关知识,请在本站搜索。

本文标签: